I am a JS beginner. Just read a couple of beginner books. I am now taking an online course and even though I thought I knew if statements this bit of code doesn't seem to run right.
Here is the simple code that is taken directly from the course teaching materials:
let stationery = "pen";
if (stationery == "pen" || "pencil") {
console.log("You have enough stationery to write the exam.");
}
else {
console.log("You do not have sufficient stationery to write the exam.");
}
On the face of it it seems ok. When I see console.log the output say: You have enough stationery to write the exam.
However, if I change the stationery variable to something else like "chalk" and rerun the if statement, the console.log result still says: You have enough stationery to write the exam.
I would expect the final else statement to kick in and show: You do not have sufficient stationery to write the exam.
This is so early on in the course that I am almost embarrassed to ask. What am I missing? The beginner books I read were before let and used var. Is it anything to do with this that is confusing my beginner's understanding?
I think this could be something to do with "truthy" values in the if statement conditionals but I don't get it.
Thanks.