+ 4

Please help me understand the problem with the code below.

<!DOCTYPE html> <html> <head> <title>Adult or not</title> <script> var isAdult= (age < 18) ? "is young": "is old"</script> </head> <body> </body> </html>

29th May 2019, 4:41 PM
Lucia Chebi
Lucia Chebi - avatar
1 Answer
+ 5
You have no variable named 'age' so it doesn't know what to compare the number 18 with. You probably want to output the resulting string after the comparison using document.write(isAdult) - (keep in mind I'm not a web developer) but this seems to do what you want: <!DOCTYPE html> <html> <head> <title>Adult or not</title> <script> var age = 29 var isAdult = (age < 18) ? "is young": "is old" document.write(isAdult) </script> </head> <body> </body> </html>
29th May 2019, 5:07 PM
Cluck'n'Coder
Cluck'n'Coder - avatar