0

Java Script Switch

Please tell me how to write this code in switch format <script> var firstnum=prompt("Enter the first number"); var secondnum=prompt("Enter the second number"); if(firstnum>secondnum) { document.write("oh "+ firstnum + " is big then "+ secondnum ); } else if(secondnum>firstnum) { document.write( "oh "+ secondnum + " is big then "+ firstnum); } else if (firstnum==secondnum) { document.write( "Sorry! Your Both Number are equal Try Another"); } else { document.write("Error Please enter a valid number"); } </script>

24th Nov 2018, 2:32 AM
Dheeraj Khodia
Dheeraj Khodia - avatar
2 Answers
+ 2
var x = first - second; switch (Math.sign(x)) { case 1: ... break; case - 1: ... break; case 0: ... }
24th Nov 2018, 2:38 AM
Gordon
Gordon - avatar
+ 1
I think if else statement is best option here
24th Nov 2018, 2:41 AM
Divanshu Mehta