-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprice_calc.html
More file actions
34 lines (25 loc) · 1.18 KB
/
price_calc.html
File metadata and controls
34 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!-- Author: NerdOfCode -->
<html>
<center>Enter weekly allowance  <input type="text" id="money"></input><br><br>
Enter money saved:     <input type="text" id="saved"></input><br><br>
Enter desired cost:       <input type="text" id="cost"></input><br><br>
<button onclick="moneycalc();">Submit</button></center>
</html>
<script>
//Author: NerdOfCode
function moneycalc(){
var allowance = document.getElementById("money").value;
var saved = document.getElementById("saved").value;
var cost = document.getElementById("cost").value;
var weeks = 0;
//Cast total subsidaries to Number to interpret as numb and not str
var total = Number(saved) + Number(allowance);
//Where the magic happens
if (total>=cost){alert("You already have enough!!!");}
if (!allowance){document.write("Error: Please enter an allowance<br>");}
if (!cost){document.write("Error: Please enter a cost<br>");}
//if (allowance>=cost){alert("You will have enough within the week");}
while (cost > total){weeks++;total = Number(allowance) + Number(total);}
alert("It will take about " + weeks + " weeks to earn " + total + " dollars");
}
</script>