The switch keyword - EXCERCISE

Hi to everyone. It is not the firs time that this happened to me. So I need help

I write my code and the output is correct, but still, the console is saying that is not. I can not finde my error. Could anyone help me pointing out what it is??

I attached you my code

let athleteFinalPosition = ‘third place’;

switch (athleteFinalPosition)
{case ‘first place’:
console.log(‘You get the gold medal!’);
break;
case ‘second place’:
console.log(‘You get the silver medal!’);
break;
case ‘third place’:
console.log(‘You get the bronze medal!’);
}

Many thanks!!!

Try using " " instead of ’ '. Characters (single letters) use ’ '.

1 Like

You need another break at the last case or the switch won’t end itself.

1 Like

@janneslohmeijer would be correct here @andresnovoa862696080

switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    // expected output: "Mangoes and papayas are $2.79 a pound."
    break;
  default:
    console.log('Sorry, we are out of ' + expr + '.');
}
1 Like

Yep, and since I almost forgot about the default :stuck_out_tongue: .

You may want to add a default too with the purpose of error handling in case someone did not pass a correct string. Might even be in the exercise but I am not sure.

1 Like

that worked! Thanks!

1 Like

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