4.2 added
This commit is contained in:
25
w4_2_recursion_countdown/index.js
Normal file
25
w4_2_recursion_countdown/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
function countDown(n) {
|
||||
if (n == 0) {
|
||||
celebrate();
|
||||
setText('Happy New Year!');
|
||||
} else {
|
||||
setText(n);
|
||||
setTimeout(() => {
|
||||
countDown(n - 1);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
const n = 10;
|
||||
setText(n);
|
||||
countDown(n);
|
||||
|
||||
// Helpers
|
||||
function setText(n) {
|
||||
document.getElementById('countdown').textContent = n;
|
||||
}
|
||||
|
||||
function celebrate() {
|
||||
const jsConfetti = new JSConfetti();
|
||||
jsConfetti.addConfetti();
|
||||
}
|
||||
Reference in New Issue
Block a user