-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path02-change.html
More file actions
37 lines (31 loc) · 949 Bytes
/
02-change.html
File metadata and controls
37 lines (31 loc) · 949 Bytes
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
<!-- Makes change for currency in USD -->
<!DOCTYPE html>
<html>
<body>
<input type="text" value="" id="text_cents" />
<input type="button" value="Make Change" id="button_compute" />
<script>
var button = document.getElementById('button_compute');
button.onclick = processClick;
function processClick() {
var cents = document.getElementById('text_cents').value;
if (cents) {
makeChange(cents);
} else {
alert('Not a valid input');
}
}
function makeChange(num) {
var quarters = Math.floor(num/25);
num = num%25;
var dimes = Math.floor(num/10);
num = num%10;
var nickels = Math.floor(num/5);
num = num%5;
var pennies = num;
alert('You get:\n' + quarters + ' quarters\n' + dimes + ' dimes\n' +
+ nickels + ' nickels\n' + pennies + ' pennies\n');
}
</script>
</body>
</html>