What did I do wrong here?
<title>This is a math facts program</title>
var Budget = window.prompt("Enter your budget");
var name = window.prompt("Enter the item name");
var price = window.prompt("Enter the item price");
var price = 0;
var savings = parseInt(budget - price);
while (savings > 10)
alert("Savings before purchase " + savings);
name = prompt("Enter the name of the item",0);
price = prompt("Enter the price of the item",0);
alert("savings after purchase " + savings);
if(wksum <= 10)
document.write("You have gone overbudget")
"My code doesn't work" doesn't tell us anything. We already knew that from that fact that you're looking for help in this forum. What we need is a concrete error description. Does the result have a small rounding error? Does your whole browser crash as soon as the script runs? Something in between?
What I do see is a whole bunch of careless mistakes and logical errors. There's undefined and unused variables, typos, the whole math part in the loop is missing etc.
Since fixing all those error most probably takes longer than simply rewriting the 10 lines, I suggest the following:
- Take a deep breath.
- When you know exactly how to go about the task, start writing your actual code. Do it slowly and carefully. Write the code step by step and test each portion before moving on.
- Now your code "works".
Writing down the code in one go without planning or testing it works for very experienced programmers who rarely make mistakes. It does not work for beginners who've just begun to learn the language. So don't do it. What happens is that you'll be stuck with a bunch of broken code and no clue of what to do next.
Edit :Thanks for the advice