Skip to content

Commit

Permalink
session 20: event exercices
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeppy committed Apr 21, 2023
1 parent 2616259 commit 24f9291
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions session20/exercice1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button>Lancer le décompte</button>
<script src="script.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions session20/exercice1/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let button = document.querySelector("button");
let secondes = 10;
let interval;

button.addEventListener('click', start);

function start() {
interval = setInterval(decompte, 1000);
}

function decompte() {
secondes--;
if (secondes > 0) {
document.querySelector('body').innerHTML += "<br/>" + secondes;
} else {
stop();
}
}

function stop() {
clearInterval(interval);
}
14 changes: 14 additions & 0 deletions session20/exercice2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button>Afficher</button>
<p>Le texte caché.</p>
<script src="script.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions session20/exercice2/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let button = document.querySelector("button");
let p = document.querySelector("p");
let hidden = true;

p.style.display = "none";

button.addEventListener('click', () => {
if (hidden) {
button.textContent = "Cacher";
p.style.display = "";
} else {
button.textContent = "Afficher";
p.style.display = "none";
}
hidden = !hidden;
});

0 comments on commit 24f9291

Please sign in to comment.