Ask Question
3 May, 14:55

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

+4
Answers (1)
  1. 3 May, 16:02
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers