Javascript prompt variable and parse it to number - Javascript Data Type

Javascript examples for Data Type:Number

Description

Javascript prompt variable and parse it to number

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
window.onload=function(){//www .j a  v a2  s . c  o m
    var num1 = prompt("How much money do you have?");
    var num2 = prompt("How much money will you add?");
    var a = parseInt(num1);
    var b = parseInt(num2);
    var result = 0;
    function addTwoNumbers(a,b) {
        return a + b;
    }
    console.log("you will have " + addTwoNumbers(a, b));
}

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials