Test not pass but passes on console

Tell us what’s happening:
For the switch challenge I wrote the code bellow. It passes when I test it on my console bud doesn’t passes when I run the tests on the website. I cant see where is my mistake.

Your code so far


function caseInSwitch(val) {
var answer = "";
// Only change code below this line

switch(val) {
case 1:
  console.log("alpha");
  break;
case 2:
  console.log("beta");
  break;
case 3:
  console.log("gamma");
  break;
case 4:
  console.log("delta");
  break;        
}

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

caseInSwitch();

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Selecting from Many Options with Switch Statements

Link to the challenge:

You need to return the correct value rather than console.log the value.

1 Like

Thank you. But there is any explanation for that. I’ve always to return on tests for example?

console.log is only used to make the output viewable in the console. In order for a function to return data that can be used by other code, you need to use return. In general you want return, especially since it was given as part of the function in the starter code.

1 Like