Forum : Can we use conditional statements in switch cases?
Brief description  about Online courses   join in Online courses
View Sasmita  Patnaik 's Profile

Can we use conditional statements in switch cases?

Can we use this syntax? I mean can we use conditional statements in switch cases?

Switch (m)
{
case ("m>10
Asked by Sasmita Patnaik | Aug 1, 2010 |  Reply now
Replies (3)
View sasmita patnaik 's Profile
Thanks a lot.
Aug 9, 2010
View mansoor ali 's Profile
Ofcourse we can, Here's the script:

<html>
<head>

<title>Assignment 25 - Task 8</title>
<script language="javascript">
function pyr()
{

n = document.getElementById("input1").value

switch (true) {
case ((n<=100)&&(n>89)):
alert("A Grade")
break;

case ((n<=90)&&(n>79)):
alert("B Grade")
break;

case ((n<=80)&&(n>69)):
alert("C Grade")
break;

case ((n<=70)&&(n>59)):
alert("D Grade")
break;

case ((n<=60)&&(n>49)):
alert("E Grade")
break;

case ((n<=50)&&(n>0)):
alert("F Grade")
break;

default:
alert("Enter Marks only between 0-100")

}




}



</script>


</head>

<body>
<form>
Enter Marks between 0 and 100:
<input id="input1" type="text" />
<input type="button" value="submit" onclick="pyr()" />
</form>






</body>
</html>
Aug 6, 2010
View teacher siliconindia 's Profile
NO... switch parameter is to select particular case..
Aug 3, 2010