So, I’m learning if statements and they seem pretty straight forward so far. However, I’m a little bit confused on how “=” and “===” works with these?
so, normally “=” assigns
and “===” is a strict comparison
however, when I try to use “===” in the example below it will always return default no matter what the value of “roll” is. This confused me and I decided to simply put “=” and the code worked as intended.
can someone explain what is going on here? Shouldn’t this be working with “===”?
let roll = 5;
switch(roll) {
case roll = 1:
console.log('you rolled a 1');
break;
case roll = 2:
console.log('you rolled a 2');
break;
case roll = 3:
console.log('you rolled a 3');
break;
case roll = 4:
console.log('you rolled a 4');
break;
case roll = 5:
console.log('you rolled a 5');
break;
case roll = 6:
console.log('you rolled a 6');
break;
default:
console.log('your turn is skipped! Sorry!')
}