scrimba
Learn Basic JavaScript
Replacing If Else Chains with Switch
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Replacing If Else Chains with Switch
AboutCommentsNotes
Replacing If Else Chains with Switch
Expand for more info
index.js
run
preview
console
function chainToSwitch(val) {
var answer = "";
// Only change code below this line

if (val === "bob") {
answer = "Marley";
} else if (val === 42) {
answer = "The Answer";
} else if (val === 1) {
answer = "There is no #1";
} else if (val === 99) {
answer = "Missed me by this much!";
} else if (val === 7) {
answer = "Ate Nine";
}

// Only change code above this line
return answer;
}

// Change this value to test
chainToSwitch(7);
Console
"High"
,
index.html
-1:47