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
index.ts
and:
  1. Create a description variable to hold the feedback text
  2. Write a switch statement that checks the grade value and sets the appropriate description:
    • 'A' β†’ "Excellent"
    • 'B' β†’ "Good"
    • 'C' β†’ "Satisfactory"
    • 'D' β†’ "Needs Improvement"
    • 'F' β†’ "Failing"
    • Any other value β†’ "Invalid grade"
πŸ’° 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!

Please set the playground first

Loading "Switch Statements"
Loading "Switch Statements"
Login to get access to the exclusive discord channel.
Loading Discord Posts