+ 1

[solved] I need help with this java script program

alert ("type in your name") var x = prompt() alert ("type in your age") var y = prompt() alert ("do you want to print? \ntype yes or no") var z = prompt() if (z == "yes") { document.write ("name: " + x) document.write ("age: " + y) if (y > 18) { document.write("adult") } if (y <== 18) && (y > 12) { document.write("teenager") } if (y <== 12) && (y > 10) { document.write("tween") } if (y <== 10) { document.write("child") } }

20th Jul 2022, 3:13 AM
Jonathan Cuppen
Jonathan Cuppen - avatar
6 Answers
+ 2
Jonathan Cuppen 2 problems. 1. y <=. y <== is invalid syntax 2. if(condition){statement} Your synax is: if (condition)(condition){statement} alert ("type in your name") var x = prompt() alert ("type in your age") var y = prompt() alert ("do you want to print? \ntype yes or no") var z = prompt() if (z == "yes") { document.write ("name: " + x) document.write ("age: " + y) if (y > 18) { document.write("adult") } if (y <= 18 && y > 12) { document.write("teenager") } if (y <= 12 && y > 10) { document.write("tween") } if (y <= 10) { document.write("child") } }
20th Jul 2022, 3:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
I didnā€™t see the isolated equals sign instead of the double equals
20th Jul 2022, 3:35 AM
Jonathan Cuppen
Jonathan Cuppen - avatar
+ 1
Thanks!
20th Jul 2022, 3:35 AM
Jonathan Cuppen
Jonathan Cuppen - avatar
+ 1
Adding to Rik's answer ... You don't have to display an alert box before reading user's input. The prompt() method accepts a string argument that shows when asking for input. var uName = prompt("Type in your name:"); var uAge = Number(prompt("Type in your age:")); Notice the use of Number() method above to try and convert given input into a numeric value so we can do numeric comparisons proportionally. The prompt() method returns given input as a string, so a conversion from string to number is in order where we want to work with the input as a number.
20th Jul 2022, 3:57 AM
Ipang
0
I already tried that
20th Jul 2022, 3:33 AM
Jonathan Cuppen
Jonathan Cuppen - avatar
0
Never mind
20th Jul 2022, 3:34 AM
Jonathan Cuppen
Jonathan Cuppen - avatar