Exercise:
The if/else statement does not work. Try to fix it.
Hint
Hint: Some curly braces are missing.
Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <p id="demo">Display the result here.</p> <script> var greeting; var hour = new Date().getHours(); if (hour < 18) { greeting = "Good day"; else greeting = "Good evening"; } document.getElementById("demo").innerHTML = greeting; </script> </body> </html>
Result:
Show Answer
Correct Code:
<!DOCTYPE html> <html> <body> <p id="demo">Display the result here.</p> <script> var greeting; var hour = new Date().getHours(); if (hour < 18) { greeting = "Good day"; } else { greeting = "Good evening"; } document.getElementById("demo").innerHTML = greeting; </script> </body> </html>
Correct Result:
Hide Answer
Privacy Policy