New to JavaScript

Hi there, I’m learning conditional statements for JavaScript. Everything before this was going well, however the past couple assignments I had to click “Give Me Solution” because my answer just wouldn’t compute. For my conditional statements exercise I’m using switch to not have to type out if else if statements. I’m like 100% sure I have this inputed correctly but it’s saying its not. This is what I have. I’m really confused on spacing and entering… if that makes sense. Idk if I’m supposed to enter or space or just when to. Should the brace bracket be next to the end of the break? I’m so confused. Sorry if this makes no sense. Just started today. Thank you!

let athleteFinalPosition = ‘first place’;

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

When I run this, it gives me an error, then I have it give me the solution and I swear there is nothing different. Correct code v

let athleteFinalPosition = ‘first 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!’);
break;
default:
console.log(‘No medal awarded.’);
break;
}

You can find description/examples of switch here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

switches rarely have anything to offer over if-statements.

If you have two pieces of code where one “works” and the other doesn’t then clearly they are different and it is your method of comparison that is lacking. Generally when comparing things involving programming you’ll want to make an exact comparison such that not a single character can be different without you knowing. In this case eyeballing it is enough to see that they’re not the same amount of lines.

You don’t have a default coded in :wink: .

default:
console.log(‘No medal awarded.’);
break;

Also if you don’t have the exact text as stated in the assignment it often notes it as wrong. In this case
console.log(‘You got a gold medal!’); should be console.log(‘You get the gold medal!’);.

Note that the code checker just compares your code to what it should be, any alteration might cause the assignment return a false.

Oh gosh I’m embarrassed… thank you. Just started yesterday, I think I was a bit tired. Thank you!

Sure no problem. Don’t feel embarrassed. Code wise you were right on track, its just that the code checker is sometimes quite relentless.