Review this code snippet: var time = 15; var greeting; if ( time < 12 ) { greeting = “good morning”; } else if ( time < 18 ) { greeting = “good afternoon”; } else { greeting = “good evening”; } console.log(greeting); What is the message that gets printed to the console?

Respuesta :

Answer:  good afternoon

Explanation:

We're given that time = 15

From this, we see that time < 12 evaluates to false, because 15 is not smaller than 12. Put another way, 15 < 12 is false.

But time < 18 is true since 15 < 18 is true. So we execute the second block of code and have the greeting variable be set to the string "good afternoon". This is what's displayed to the console without any quotes of course.

Otras preguntas