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.