If the way it’s formatted in this post is the way you’ve actually written it, then you’ll need to fix that.
Before:
//switch final position to get different answers
let runnerFinalPosition = 'fourth place'
if (runnerFinalPosition === 'first place') {console.log('You were the fastest runner!')}
else {console.log('Sorry, you were not the fastest runner.')};
switch (runnerFinalPosition) {case 'first place': console.log('You\'ve won GOLD!')
break;
case 'second place': console.log('You\'ve won SILVER!')
break;
case 'third place': console.log('You\'ve won BRONZE!')
break;
default: console.log('You have not won a medal.')
break;
}
if (runnerFinalPosition === 'first place' || 'second place' || 'third place') {console.log('This means you\'ve placed in the final top three!')}
else {console.log('You have not placed in the final top three.')};
after:
//switch final position to get different answers
let runnerFinalPosition = 'fourth place'
if (runnerFinalPosition === 'first place') {
console.log('You were the fastest runner!')
}
else {console.log('Sorry, you were not the fastest runner.')};
switch (runnerFinalPosition) {
case 'first place':
console.log('You\'ve won GOLD!')
break;
case 'second place':
console.log('You\'ve won SILVER!')
break;
case 'third place':
console.log('You\'ve won BRONZE!')
break;
default:
console.log('You have not won a medal.')
break;
}
if (runnerFinalPosition === 'first place' || 'second place' || 'third place') {
console.log('This means you\'ve placed in the final top three!')
}
else {
console.log('You have not placed in the final top three.')
};
This will allow everything to run as coded, but you should also make sure you add semicolons at the end of lines where they are omitted (after let...
and each console.log()
).
The reason the else
is not executing is because your if
statement always evaluates to true
.
That’s because when runnerFinalPosition
is not equal to the value you’re comparing it to, it is returning the next value, because you’ve formatted it with double pipes (||
), which is a logic expression.
Basically…
let runnerFinalPosition = "x";
console.log(runnerFinalPosition === "x" || "y");
“x”
and
let runnerFinalPosition = "a";
console.log(runnerFinalPosition === "x" || "y");
“y”
because the bit after ||
is returned if the bit before it is false
.
Since you’re either returning true
(if runnerFinalPosition
is equal to the string you compare it against) or a string (if it’s false), the if
statement will always evaluate to true
. That’s simply because a string with content is equal to true
, while an empty string is false
:

Therefore, in order to fix this, you need to switch from using the ||
operator like this:
if (x === "abc" || "xyz")
to using it like this:
if (x === "abc" || x === "xyz")
…does that make sense?
I’m deliberately not giving you the full answer because I think you’ll be better off if you figure it out yourself, based on what I’ve said here. If you understand it, rather than just knowing it, you’ll be able to debug better going fowards.
Let me know if you have any further questions!