You are tasked with writing a program that outputs a customization message based on the time of day. Which code snippet correctly uses branching to output 'Good morning!' when the variable 'currentTime' is less than 12?
You selected this option
if (currentTime > 12) { print('Good morning!'); }
You selected this option
if (currentTime = 12) { print('Good morning!'); }
You selected this option
if (currentTime < 12) { print('Good morning!'); }
You selected this option
if (currentTime == 12) { print('Good morning!'); }
The correct answer checks if 'currentTime' is less than 12 using a less than '<' operator within a conditional statement (if). If the condition evaluates to true, it correctly executes the code within the block that prints the 'Good morning!' message. Option B is incorrect because it uses an assignment operator '=' instead of a comparison operator. Option C incorrectly uses '==' which tests for equality, not less than. Option D incorrectly uses a greater than '>' operator, which doesn't match the requirement of 'less than 12'.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is branching in programming?
Open an interactive chat with Bash
What is the difference between '=' and '==' in programming?