Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding 3 Values From Prompt

    Can anyone help me out with the code (or pointing me to a similar code)?

    I am creating childrens numeracy website and I need a script that upon a button click loads a prompt window. The user can enter 3 integers (into 3 different prompts) and the added value of the 3 integers is printed to the screen.

    Didn't really know any JavaScript untill about 5 minutes ago so please be kind!

    Regards,

    Anna

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here a webpage that does what I think you want:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    	<head>
    		<title>
    		
    		</title>
    		
    		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
    		<meta http-equiv="content-style-type" content="text/css" />
    		<meta http-equiv="content-script-type" content="text/javascript" />
    		
    		<script type="text/javascript">
    		/* <![CDATA[  */	
    			function add3numbers()
    			{
    				var firstNum = parseFloat(prompt('Please enter the first number', ''));
    				var secondNum = parseFloat(prompt('Please enter the second number', ''));
    				var thirdNum = parseFloat(prompt('Please enter the third number', ''));
    				
    				var result = firstNum + secondNum + thirdNum;
    				
    				var resultString = document.createTextNode('The result is: ' + result);
    				var resultSpan = document.createElement('span');
    				resultSpan.appendChild(resultString);
    				
    				document.body.appendChild(resultSpan);
    			}
    		/* ]]> */
    		</script>
    	</head>
    
    	<body>
    		<button onclick="add3numbers()">Click here to add 3 numbers</button>
    	</body>
    </html>
    It works with floating-point numbers also.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •