+ 1
Java Script Comparsion Operators
select.onchange= function(){ (select.value==="black")?update("navy","gold","white"):update("red","indigo","white"); My question is what is the "?" doing on this function. The code is part of a theme changer
3 Answers
+ 2
select.onchange = function() {
(select.value === "black") ? update("navy, "gold", "white") : update("red", "indigo", "white");
}
It's called the ternary operator and is basically the same as an if-statement
select.onchange = function() {
if (select.value === "black") update("navy", "gold", "white");
else update("red", "indigo", "white");
}
These two codes does exactly the same.
+ 1
WOW!!!!!!
0
I looked all over my notes couldn't find it and then I Quarantine the code and it gave some error message. Thnaks I was kinda stumped. I did figure it was working as an else statement.