Simple Switch Statement


/ Published in: JavaScript
Save to your folder(s)

Very basic switch statement.


Copy this code and paste it in your HTML
  1. function switchTest(x){
  2. switch(x){
  3. case 1:
  4. console.log("x equals 1");
  5. return x;
  6. case 2:
  7. console.log("x equals 2");
  8. return x;
  9. case 3:
  10. console.log("x equals 3");
  11. return x;
  12. default:
  13. console.log("x doesn't equal 1 to 3");
  14. return x;
  15. }
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.