...

View Full Version : Switch Case Help



jason_kelly
01-11-2012, 07:51 PM
Hi There,

I need your help,

I can't seem to get this work, which it theorecticly should work any ideas?

<script>

var x = 3

switch(x){
case x > 0:
alert("overdue")
break

case x = 0:
alert("due today")
break

case x < 0:
alert("will be due")
break
}
</script>

Much thanks for everyones help.

Cheers,

Jay

xelawho
01-11-2012, 08:11 PM
I think you're kind of misusing the switch, which should be used to compare the value of a variable against another (not evaluate it relatively like you have it) it but if you really want to do it that way this would be the hack (note that I changed your case x = 0: to case x == 0: to avoid the value of x getting redefined midway through the switch):



<script>

var x = 3;

switch(true){
case x > 0:
alert("overdue")
break

case x == 0:
alert("due today")
break

case x < 0:
alert("will be due")
break
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum