Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikepro44

macrumors member
Original poster
May 18, 2008
86
0
Using java script I'm trying to have so you are prompted to put numbers in until you press 0, after that it will calculate and add all the numbers you put in. I think I'm getting pretty close to it..?

Anyways, if someone could help me out that would be awesome:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
var price;
var total;
var temp = 0
tax = 1.07
prompt("please enter price");
while(!price)
{
price = parseFloat(prompt("please enter a price or 0 to stop"));
if(price != 0)
{
temp+=price;
}
}

document.write("You total is $"+total.toFixed(2));
</script>
</body>
</html>
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Here you go,
PHP:
<script type="text/javascript">
function PromptUser() {
  var total = 0;
  tax = 1.07;
  do {
    var price = parseFloat(prompt("please enter a price or 0 to stop"));
    if (price !== 0) {
      total += price;
    }
  } while (price !== 0);
  OutputTotal(total);
}
function OutputTotal(t) {
  document.getElementById('total').innerHTML = "You total is $"+ t.toFixed(2);
}
window.onload = PromptUser;
</script>
</head>
<body>
<div id="total"></div>
</body>
</html>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.