Ask Question
12 July, 07:32

Something is wrong with the logic in the program above. For which values of time will the greeting "Good Morning!" be displayed? var time = promptNum ("What hour is it (on a 24 hour clock) ?"); var greeting = ""; if (time < 6) { greeting = "It is too early!"; } else if (time < 20) { greeting = "Good Day!"; } else if (time < 10) { greeting = "Good Morning!"; } else { greeting = "Good Evening!"; } console. log (greeting);

+5
Answers (1)
  1. 12 July, 11:27
    0
    There is logic problem in condition of elseif statement that is (time<20).

    Explanation:

    elseif (time<20) will be true for time<10 that means program will never greet good morning as to make logic correct either change condition from elseif (time<20) to elseif (time=10). Or change the order of condition like check first for elseif (time<10)

    solution 1

    if (time < 6) { greeting = "It is too early!"; }

    else if (time = 10) { greeting = "Good Day!"; }

    else if (time < 10) { greeting = "Good Morning!"; }

    else { greeting = "Good Evening!"; }

    console. log (greeting);

    solution 2

    if (time < 6) { greeting = "It is too early!"; }

    else if (time < 10) { greeting = "Good Morning!"; }

    else if (time < 20) { greeting = "Good Day!"; }

    else { greeting = "Good Evening!"; }

    console. log (greeting);
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Something is wrong with the logic in the program above. For which values of time will the greeting "Good Morning!" be displayed? var time = ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers