我在学习如何使用javascript做switch语句。你们能帮我怎么把这个转换成switch语句吗?javascript:switch语句
if (x == ix && y == iy){//should be the default
x.style.backgroundColor = 'white';
}
if(x < ix){
x.style.backgroundColor = 'red';
}
else if(x > ix){
x.style.backgroundColor = 'blue';
}
if(y < iy){
x.style.backgroundColor = 'green';
}
else if(y > iy){
x.style.backgroundColor = 'yellow';
}
我不会重写这个使用switch语句,它也不是真的可能。顺便说一句,如果'x == ix'但是'y!= iy',那么你可能会遇到某种情况,通过裂缝落下。你应该仔细检查你的逻辑。 –
你对结果做了一个小图示吗? 'y'的值优先于'x'的优先级。 –
什么是'x','y','ix'和'iy'? – Taurus