4.2 added
This commit is contained in:
19
w4_2_recursion_countdown/index.html
Normal file
19
w4_2_recursion_countdown/index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=<device-width>, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"></script>
|
||||
|
||||
<script defer src="index.js"></script>
|
||||
|
||||
<h1 id="countdown">x</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
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();
|
||||
}
|
||||
15
w4_2_recursion_countdown/style.css
Normal file
15
w4_2_recursion_countdown/style.css
Normal file
@@ -0,0 +1,15 @@
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-color: #f0f0f0;
|
||||
font-family: Arial, sans-serif;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
#countdown {
|
||||
font-size: 10rem;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
Reference in New Issue
Block a user