Switch doesn't work

Tell us what’s happening:

Your code so far


function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(answer){
 case 1:
 "alpha";
 break;
 case 2:
"beta";
 break;
 case 3:
"gamma";
 break;
 case 4:
"delta";
 break;
 default:
 break;
  }
  
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements

The switch is working fine. The problem is you are just have a string on each line after the case line. Since your return statement returns the answer variable and you want it to return those values you wrote, what should you do so answer has the correct value when the return statement executes?

switch(val){//not “answer”
case 1:
answer=“something”;
break;
}

case 1:
answer = “alpha”;
break;
case 2:
answer = “beta”;
break
etc…
I had the same issue earlier. It stump me for a bit also.

Then why does the example for this challenge not use ‘answer=’ ? The example uses ‘console.log()’ instead of ‘answer.’ So why doesn’t it work if I use ‘console.log(“alpha”)’, etc. in my code ? And if that is a completely different function than using ‘answer’ then why is it being used in the example? If it does something different then it is not an example of what your code is supposed to do, is it?

This is the example provided for this challenge:

switch(lowercaseLetter) {
case “a”:
console.log(“A”);
break;
case “b”:
console.log(“B”);
break;
}

It just seems like if they want you to do something different than what is in the example then the instructions need to explain that they want you to do something different. Obviously I am new to JavaScript, but that's what these lessons are for, right? Did I miss something?

console.log("a");

simply prints out the letter a to the console. it does not assign the letter a to any variable.

answer = 'a';

assigns the letter ‘a’ to the variable ‘answer’.

Ok, thank you. I also looked up what the console.log function was supposed to do. But then why is that in the example ? Did they just happen to use an example of code that does something entirely different than the challenge? It is never explained in the lesson what the console.log in the example accomplishes, so it is a bit of a leap for someone new to coding to understand that I need to use something different to fulfill the challenge. If the purpose and function of the example were explained, or the example were in the same vein as the challenge it would make a lot more sense.