if, else if, else
You should see
Warm
empty
but [] itself is truthy!
B
pass
no user anonymous user Adafizzbuzz(n) for 1–15: multiples of 3 print Fizz, of 5 print Buzz, of both print FizzBuzz. Order of the checks matters — why?const temperature = 31if (temperature > 35) {console.log("Heat warning")} else if (temperature > 25) {console.log("Warm")} else {console.log("Cold")}
Bind temperature to 31.
temperature | 31 |
All 4 steps as a table
| Step | Line | What happened | Variables now |
|---|---|---|---|
| 1 | 1 | Bind temperature to 31. | temperature = 31 |
| 2 | 2 | Evaluate 31 > 35 → false. Skip this block. | |
| 3 | 4 | Evaluate 31 > 25 → true. Enter this block. | |
| 4 | 5 | Print. Then jump past the whole chain — the else is never considered. |
Assignment in a condition: if (x = 5)
let role = "guest"
if (role = "admin") {
console.log("access granted")
}
console.log(role)access granted
adminNo error — a silent bug. = assigns; the expression role = "admin" evaluates to "admin", which is truthy, so the block always runs and role is now "admin". You meant ===.
Use ===. Linters flag no-cond-assign; turn ESLint on from day one (Module 14).
let role = "guest"
if (role === "admin") {
console.log("access granted")
}
console.log(role) // guest