Review this code snippet: var time = 15; var greeting; if ( time < 12 ) { greeting = “good morning”; } else if ( time < 18 ) { greetin

Question

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?

in progress 0
Latifah 4 years 2021-08-22T20:28:36+00:00 1 Answers 19 views 0

Answers ( )

    0
    2021-08-22T20:29:42+00:00

    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.

Leave an answer

Browse

Giải phương trình 1 ẩn: x + 2 - 2(x + 1) = -x . Hỏi x = ? ( )