Q: You need a conditional statement that checks if a variable equals “In progress,” “Completed,” or “Canceled.” Different code needs to run, depending on what the variable equals. A default block of code needs to run if the variable does not equal any of the values. What conditional statement is most appropriate?
A. Incorrect: Error handling is not a conditional statement.
B. Incorrect: A ternary operation only checks if a value or expression is true. Based on the results, the operation takes different actions.
C. Incorrect: The if statement does not allow multiple branches of code depending on a value. If statements check if the expression is true or false and then runs or doesn’t run the code.
D. Correct: The switch statement allows you to use cases. If the case matches the value of the switch expression, then a specific code block can run. A default case can also be used when no other cases match.