24 Hour Clock explainer

Aim of the puzzle: Create an if statement.
Walk through of solution: The code contains a variable declaration and an if statement. The variable is named hour and has a random value from 1-24. The if statement prints 'good morning' if hour is less than 13. In this puzzle, you’ll add another if statement that prints 'good afternoon' if hour is greater than 12.

To complete the puzzle, add another if statement below the code. The if statement should check if hour is greater than 12. If it is, it should print 'good afternoon'.

This is the first time you need to type out an entire if statement on your own, so don’t forget to type:

  • The if keyboard
  • The test inside the parentheses ()
  • The code to run if the test is true inside the code block {}

Sample code solution:

let hour = pickRandom(24);
console.log(hour + ':00');

if (hour < 13) {
   console.log('good morning');
if (hour > 12) {
   console.log('good afternoon');

Javascript Concepts: variables, console.log, if statement, comparison operator, assignment operator, strings, numbers