How to add,subtract by using function and Switch statement in Javascript

How to create addition, subtraction by using function and switch statement.

<!--DOCTYPE html--> <html> <head> <title></title> <script> alert("1. Addition "+"\n"+"2.Subtraction"); var n1,n2,res; var ch=parseInt(prompt("select your choice:")); // string (parseInt()=>convert into number) function inp(){ n1=parseInt(prompt("Enter 1st nos:")); n2=parseInt(prompt("Enter 2nd nos:")); } switch(ch){ case 1: inp(); //calling res=n1+n2; alert("ADDITION (N1+N2):"+res); break; case 2: inp(); //calling res=n1-n2; alert("SUBTRACTION (N1-N2):"+res); break; default: alert("Invalid"); } </script> <body> </body> </html>

agyanadda

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 $type={blogger}:

Post a Comment