-
Notifications
You must be signed in to change notification settings - Fork 0
/
dollar.js
60 lines (56 loc) · 1.51 KB
/
dollar.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var dollarCalc = function(amount) {
var hundred = 0;
var fifty = 0;
var twenty = 0;
var ten = 0;
var five = 0;
var one = 0;
var quater = 0;
var dime = 0;
var nickel = 0;
var penny = 0;
if (amount > 0 && typeof(amount) === "number") {
while ((amount / 100) >= 1) {
amount -= 100;
hundred++;
}
while ((amount / 50) >= 1) {
amount -= 50;
fifty++;
}
while ((amount / 20) >= 1) {
amount -= 20;
twenty++;
}
while ((amount / 10) >= 1) {
amount -= 10;
ten++;
}
while ((amount / 5) >= 1) {
amount -= 5;
five++;
}
while ((amount / 1) >= 1) {
amount -= 1;
one++;
}
while ((amount / 0.25) >= 1) {
amount -= 0.25;
quater++;
}
while ((amount / 0.10) >= 1) {
amount -= 0.10;
dime++;
}
while ((amount / 0.05) >= 1) {
amount -= 0.05;
nickel++;
}
while ((amount / 0.01) >= 1) {
amount -= 0.01;
penny++;
}
}
return ("Hundreds: " + hundred + " Fifties: " + fifty + " Twentys: " + twenty + " Tens: " + ten + " Fives: " + five + " Ones: " + one + " Quarters: " + quater + " Dimes: " + dime + " Nickels: " + nickel + " Pennies: " + penny);
};
document.write(dollarCalc(288.97));