You are tasked with writing a program that outputs a customized 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?
if (currentTime = 12) { print('Good morning!'); }
if (currentTime == 12) { print('Good morning!'); }
The correct answer checks if 'currentTime' is less than 12 using a less than '<' operator within a conditional if statement. The incorrect options use the wrong operators for this specific task. One uses the assignment operator (=), which assigns a value rather than comparing it. Another option incorrectly tests for exact equality (==). The final incorrect option uses the 'greater than' (>) operator, which is the logical opposite of what is required.
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 the purpose of the '<' operator in programming?
Open an interactive chat with Bash
Why is '=' not correct in conditional statements?
Open an interactive chat with Bash
What does '==' do in programming, and why wasn’t it correct here?