Chapter practice task
Task: Show a time-based greeting and a list of your services
- Get the current hour with
new Date().getHours(). - Show “Good morning”, “Good afternoon” or “Good evening” with if/else.
- Store your services in an array.
- Loop over the array and add each service to a list on the page.
- Highlight one service if it’s marked as “popular”.
By the end of this chapter
- You can write if/else and switch statements with comparison and logical operators
- You can repeat code with for, for…of, while and forEach
- You can combine conditions and loops to build dynamic content
Quick answers for this chapter
What’s the difference between = and ===?
= assigns a value; === compares two values.
Which loop should I use?
for...of or forEach for arrays, a classic for when you need a counter.
Can a loop run forever?
Yes, if its condition never becomes false. That freezes the page, so always make sure the loop can end.