Why is the age variable undefined? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
9th Jun 2018, 3:59 AM
Eilia Zandi
Eilia Zandi - avatar
16 Answers
+ 8
Hi Ilia Zandi I'm getting the error here on my phone and on my computer. There are many syntax errors, starting from the head tag where you have a h1 tag inside of it. And the whole html and js code is very messy, it can confuse browsers and make them behave weird 😜 But the main issue is: 》Only the first input of the breakfast selection is being targetted in your JS in your input variable so the result is always going to be the same. Since all the breakfast inputs are checkboxes it has to be treated as an array and can be targetted via getElementsByName. Also the js logic has to be exactly the same as the Sides's logic, which is also an array because it has multiple checkbox options. I'm attaching your code revised. It took me some time because I had to reorganize it. I'll leave you the homework of adding label tags in the form for the Side Options and Age, I did it for the Breakfast selection so you can take it as a guide. Hope it helps you 👍 https://code.sololearn.com/WFxLrbH3IRp8/?ref=app
9th Jun 2018, 6:22 AM
Pao
Pao - avatar
+ 4
It's working fine for me.
9th Jun 2018, 4:04 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
Ilia Zandi whoops! sorry, it's attached now 😊 also I forgot to mention that I have used a different way for targetting the radio inputs to avoid getting an 'undefined menu'. If you have any question let me know 👍😊
9th Jun 2018, 6:48 AM
Pao
Pao - avatar
+ 3
works fine here
9th Jun 2018, 4:57 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Same here too..working alright
9th Jun 2018, 4:13 AM
Rohit
Rohit - avatar
+ 1
But when you run the code in the second line it says from the undefind menu why does it say undefined instead of the age of the user.
9th Jun 2018, 4:15 AM
Eilia Zandi
Eilia Zandi - avatar
+ 1
Tried all combinations but didnt got that error...can u send a screenshot
9th Jun 2018, 4:42 AM
Rohit
Rohit - avatar
+ 1
Just hit the submit button and it says: you ordered the cereal with coffee as sides from the *Undefinedmenu*.Your order will be ready in under 7 minutes. What is undefined :(
9th Jun 2018, 4:51 AM
Eilia Zandi
Eilia Zandi - avatar
+ 1
Thank you!! but the there is nothing in the link
9th Jun 2018, 6:40 AM
Eilia Zandi
Eilia Zandi - avatar
0
it wroks but in the output it says : you ordered the cereal with coffee as sides from the *Undefinedmenu*.Your order will be ready in under 7 minutes
9th Jun 2018, 4:58 AM
Eilia Zandi
Eilia Zandi - avatar
9th Jun 2018, 5:09 AM
Rohit
Rohit - avatar
9th Jun 2018, 5:14 AM
Eilia Zandi
Eilia Zandi - avatar
0
omg! when I go with my phone it works but not with it doesn't work on my pc
9th Jun 2018, 5:16 AM
Eilia Zandi
Eilia Zandi - avatar
0
ohhh something funny. when I open it in firefox it works but not in internet explorer
9th Jun 2018, 5:29 AM
Eilia Zandi
Eilia Zandi - avatar
0
yea..now that's weird....sorry but can help in it nos cuz i am not on pc right now .....i'll try it when i am pc..hope your problem get solved soon
9th Jun 2018, 5:40 AM
Rohit
Rohit - avatar
0
it works on Firefox so it's all good
9th Jun 2018, 5:41 AM
Eilia Zandi
Eilia Zandi - avatar