Where is the error in this Switch Statement?

The tests fail, but the code works? I don’t get it.

function caseInSwitch(val) {
  let 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(4);

You didn’t set the value of answer

You’re not following this instruction:

Write a switch statement which […] sets answer

The tests are looking at the return value of your function. You can check what your function returns by wrapping the function call in a console.log().

console.log(caseInSwitch(4));

If you do that you’ll see that your current implementation always return an empty string.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.