Ask 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 = 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);

+1
Answers (1)
  1. 19 June, 05:39
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers