jeudi 24 mars 2016

Javascript Addition Program

This is a javascript program for adding two numbers but the problem is the code is too big and everytime I need to change the number to the integer by parseInt so if I need to add more numbers the code will become more lengthy. How can I make it more simple?

 <!DOCTYPE html>
<html>
<head>
<title>adding</title>
</head>
<body>
<script type="text/javascript">
var x; 
var y;
var z;
var n;
var result;

x=prompt("1st number");
y=prompt("2nd number");
z=parseInt(x);
n=parseInt(y);
result= n + z;
alert(result);
</script>
</body>
</html>`

`




Aucun commentaire:

Enregistrer un commentaire