

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Conditionals
incomplete
2: Comparison Operators
incomplete
3: Logical Operators
incomplete
4: Switch
incomplete
5: Ternary Operator
incomplete
6: When to Ternary
incomplete
7: Truthy and Falsy
incomplete
8: Nullish Coalescing
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Switch statements are a way to compare a variable against multiple possible values. They are similar to if-else statements, but tend to be more readable when there are many potential options.
const os = "mac";
let creator;
switch (os) {
case "linux":
creator = "Linus Torvalds";
break;
case "windows":
creator = "Bill Gates";
break;
case "mac":
creator = "Steve";
break;
default:
creator = "Unknown";
break;
}
console.log(creator);
// Steve
Unlike some languages where fall-through doesn't happen by default, JavaScript will continue to execute the next case until it reaches a break or return statement.
99 times out of 100, you'll want to include a break/return statement after each case to prevent this behavior.
Fix the bug in the billingCost function. The "basic" plan is set correctly, but we need matches for the "pro" and "enterprise" plans, too. If the plan is:
20.050.0.Test your function with the provided cases to ensure correctness.