4.Switch


#1

var user = prompt('What you name?').toLowerCase();

switch(user) {
case 'Jake':
console.log("Welcome!");
break;
case 'Lisa':
console.log("Welcome!");
break;
case 'Tommy':
console.log("Welcome!");
break;
default:
console.log("i dont known you!");
}

Why block prints by default when you enter the current version?


#2

On line 1, you added toLowerCase to the prompt. This means any answer will be converted to lowercase letters. However, all of your cases are names starting with an uppercase letter. So if someone enters 'Jake' as an answer, toLowerCase turns it into 'jake' and your default executes.


#3

Thank you! That helped! :grinning:


#4