Jquery Switch Case Example - Jquery

How to declare switch statements using jquery?

Snippet Code

Rate this page :
  [ 0 votes]

Switch statement is used to check whether one string matched with another which stored in array. Here the switch case is performed by comparing the answer with theoperations and displayed as alert message. The simple jquery code using switching statement is given below.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type='text/javascript'> $(function(){ var a=2; var b=3; var add=a+b; var sub=a-b; var mul=a*b; var div=a/b; var op = 6; switch (op) { case add: alert('Addition'); break; case sub: alert('Subtraction'); break; case mul: alert('Multiplication'); break; case div: alert('Division'); break; default: alert('No Operation Performed'); } }); </script>


Ask Questions

Ask Question