How do you do a range using switch statement in ActionScript
For example:
score = txtScore.text
switch(score)
{
case 90 to 100: // how do you set the range?
txtScore.text = “A”;
break;
}
Thanks
How do you do a range using switch statement in ActionScript
For example:
score = txtScore.text
switch(score)
{
case 90 to 100: // how do you set the range?
txtScore.text = “A”;
break;
}
Thanks
you dont. All case comparisons are done through a strict equality (i.e. === ). You might just have to use if/else.
It can be done. You have to be a little creative though. Here’s some code for something like that.
on(release)
{
intNew = (parseInt(txtScore.text) / 10)
switch(parseInt(intNew))
{
case 10: txtGrade.text = "A";
break;
case 9: txtGrade.text = "A";
break;
case 8: txtGrade.text = "B";
break;
case 7: txtGrade.text = "C";
break;
case 6: txtGrade.text = "D";
break;
default: txtGrade.text = "F";
}
}
later
Another way to workaround the issue is to use a range function’s return value as the switch value (operand?).
For your 90-100 range, you would create a function that returns a single value for any range matches (90 in the example), and returns the original value for all others.
Example:
function rangeIt(theNumber){
return (89<theNumber && theNumber<101)?90:theNumber;
}
switch(rangeIt(myNumber)){
case 90: trace('Inside Range');break;
default: trace('Outside Range');break;
}
};
This allows the use of the switch statement on a range of values without altering the actual values.
:: Copyright KIRUPA 2024 //--