bsoto8168
10-17-2002, 06:31 PM
I have a javascript assignment that needs me to display two prompts. Each prompt asks for a number between 1 to 100. After the 2 numbers from each prompt are inputed they must be totaled and the total must be displayed on the screen.
My problem is having the script read the numbers as integers so the calculation can be done. Whats happening instead is the two numbers that I type into the prompts are being concantenated instead of being added to each other. Here is my code below:
<script>
var firstnum = prompt ("Enter a number beween 1 and 100");
var secondnum = prompt (" Enter a second number between 1 and 100");
var total = 0;
total = firstnum + secondnum;
document.writeln (total);
</script>
It is the 3 rd prompt box (Ex 1.1)
http://matrix.csis.pace.edu/~f02-cs156-s18/
My problem is having the script read the numbers as integers so the calculation can be done. Whats happening instead is the two numbers that I type into the prompts are being concantenated instead of being added to each other. Here is my code below:
<script>
var firstnum = prompt ("Enter a number beween 1 and 100");
var secondnum = prompt (" Enter a second number between 1 and 100");
var total = 0;
total = firstnum + secondnum;
document.writeln (total);
</script>
It is the 3 rd prompt box (Ex 1.1)
http://matrix.csis.pace.edu/~f02-cs156-s18/