Why is this not working in JavaScript? I'm fairly new to programming.
var material = 'wood';
if (material != ('alu'||'plastic')) {
material = 'plastic';
}
Thanks in advance!
You could use Array's methods such as indexOf:
if (['alu','plastic'].indexOf(material) >= 0) {
...
}
You instead need something like this:
if (material != 'alu' && material != 'plastic')
This is because the || operator requires an expression on both sides, meaning that you need to do a comparison on both sides.
EDIT: I changed it to && because I realized you wanted if check if the material was neither of the two.
||operator in javascript doesn't work like this.