I am doing the Basic JavaScript: Replacing If Else Chains with Switch lesson and I cant get past this one.
function chainToSwitch(val) {
var answer = "";
// Only change code below this line
switch(val) {
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
}
}
// Only change code above this line
chainToSwitch(7);
this is what I have so far, the case statements are not equaling the values.
I move the thread to the appropriate subforum and I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Note: Backticks are not single quotes.

-
When asking for help please included the link to the challenge.
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch
-
If you need help with the challenges you can click “Get Help” and then “Ask for help”. This will make a forum thread with your code and some information.
You are setting the answer
variable, but you are not returning it.
1 Like