aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/zapwai/javascript/ch-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-285/zapwai/javascript/ch-2.js')
-rw-r--r--challenge-285/zapwai/javascript/ch-2.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-285/zapwai/javascript/ch-2.js b/challenge-285/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..f1a85eb1c6
--- /dev/null
+++ b/challenge-285/zapwai/javascript/ch-2.js
@@ -0,0 +1,18 @@
+let amt = 100;
+let cnt = 0;
+for (let h = 0; h <= amt/50; h++) {
+ for (let q = 0; q <= amt/25; q++) {
+ for (let d = 0; d <= amt/10; d++) {
+ for (let n = 0; n <= amt/5; n++) {
+ for (let p = 0; p <= amt; p++) {
+ if (tally(p, n, d, q, h) == amt) {
+ cnt++;
+ }
+ }
+ }
+ }
+ }
+}
+console.log( "There are", cnt,"ways to make change for", amt,"cents.");
+function tally(p, n, d, q, h) { return p + 5*n + 10*d + 25*q + 50*h; }
+