Add curly braces to if/else statement - Javascript Statement

Javascript examples for Statement:Quiz

Description

Add curly braces to if/else statement

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var greeting;//from   ww  w . j  a va2 s. c  om
var hour = new Date().getHours();

if (hour < 18) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

document.getElementById("demo").innerHTML = greeting;
</script>

</body>
</html>

Related Tutorials