Switch Statements
Switch Statements
π¨βπΌ We've been using
if/else if chains, but when you're checking one value
against many possible matches, a switch statement is often cleaner.π¨ Open
. The starter sets
grade to 'B'.- Create a
descriptionstring - Write a
switchongradethat setsdescriptionto these exact values:'A'β"Excellent"'B'β"Good"'C'β"Satisfactory"'D'β"Needs Improvement"'F'β"Failing"- any other value β
"Invalid grade"
- Export
gradeanddescription
Required exports
grade, descriptionCompletion criteria (with grade = 'B')
graderemains"B"descriptionis"Good"
π° Use
switch with case branches and a default for all other values.Don't forget the
break statement after each case! Without it, execution
"falls through" to the next case.π¨ Once you've completed the exercise, run
node index.ts in the playground to
test your work!

