07.07 · If, else & else if / Practice · 6 min
Fix the time-of-day greeting
The greeting says morning at night. Check which branch matches first and where its range should end.
Activity 7 of 7 in If, else & else if
JavaScript Basics / 07.07
Fix the time-of-day greeting
Not started
Use clear hour ranges in a single branching chain.

Choose a message with if and else
Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)4 steps · Saved work · Instant feedback
YOUR TURN
Fix the time-of-day greeting
Use the original greeting ranges for a valid integer currentHour from 0–23: 6 up to 12 is Good Morning; 12 up to 18 is Good Afternoon; all other hours are Good Evening. Fix the conditions in this single if/else-if/else chain. Starting at 20, expect Good Evening.
Good Evening
Keep the starting inputs. Print these lines in this order, without extra output.
Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
const currentHour = 20;
if (currentHour >= 6) {
console.log("Good Morning");
} else if (currentHour >= 12) {
console.log("Good Afternoon");
} else {
console.log("Good Evening");
}Need a nudge?
The first match stops the chain
Hour 20 is at least 6, so the original first condition takes it too early. Give morning an upper limit.
Check the boundaries
Morning ends before 12. Afternoon starts at 12 and ends before 18. Combine the start and end comparisons with &&.
Reveal a possible solution
const currentHour = 20;
if (currentHour >= 6 && currentHour < 12) {
console.log("Good Morning");
} else if (currentHour >= 12 && currentHour < 18) {
console.log("Good Afternoon");
} else {
console.log("Good Evening");
}Check 5, 6, 11, 12, 17 and 18. Each should produce one greeting: Evening, Morning, Morning, Afternoon, Afternoon, Evening (with Good before each word). The source uses Evening for overnight hours too. This exercise assumes a valid integer hour; it does not validate dates or localize real time. The browser check compares current output only; instructor review can assess the expressions.
Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in