-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinsToCash.js
57 lines (44 loc) · 1.1 KB
/
coinsToCash.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
/* const piggyBank = {
pennies: 20,
nickels: 15,
dimes: 10,
quarters: 5
};
let dollarAmount = 0;
//Define that a penny = .01
// Take value of piggybank.piggies and multiply by the value of penny and put it in dollarAmount.
dollarAmount += piggyBank.pennies * .01
console.log(dollarAmount)
dollarAmount += piggyBank.nickels * .05
console.log(dollarAmount)
dollarAmount += piggyBank.dimes * .10
console.log(dollarAmount)
dollarAmount += piggyBank.quarters * .25
console.log(dollarAmount)
*/
let dollarAmount = 5.69 * 100
const piggyBank = {
"pennies" : 0,
"nickels" : 0,
"dimes" : 0,
"quarters" : 0
}
while (dollarAmount!= 0) {
if (dollarAmount >= 25) {
dollarAmount = dollarAmount-25;
piggyBank.quarters++
}
else if (dollarAmount >= 10) {
dollarAmount = dollarAmount-10
piggyBank.dimes
}
else if (dollarAmount>= 5) {
dollarAmount = dollarAmount-5
piggyBank.nickels++
}
else if (dollarAmount >= 1) {
dollarAmount = dollarAmount-1
piggyBank.pennies++
}
}
console.log(piggyBank)