-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
75 lines (49 loc) · 1.65 KB
/
main.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const start = document.querySelector("#start");
const timer = document.querySelector("#chrono");
const waldo = document.querySelector("#bout_waldo");
const result = document.querySelector("#regles");
let sec = 0;
let cent = 0;
let mill = 0;
let i = 0;
document.getElementById('chrono').innerHTML = `0${sec}` + ":" + `0${cent}`
waldo.style.top = `100px`;
waldo.style.left = `300px`;
start.addEventListener("click", () => {
const y = Math.floor(Math.random() * window.innerHeight)
waldo.style.top = `${y}px`
const x = Math.floor(Math.random() * window.innerWidth)
waldo.style.right = `${x}px`
});
const chrono = () => {
setInterval(() => {
mill++;
if (mill > 9) {
mill = 0;
}
}, 1);
cent++;
cent * 10;
if (cent > 9) {
cent = 0;
sec++;
}
document.getElementById('chrono').innerHTML=
sec < 10 ? `0${sec}` :
` ${sec}` + ":" + `${cent}${mill}`; // y'a une erreur qui fait que les cent et milli n'apparaissent qu'au parir de la 10 sec
lancement = window.setTimeout("chrono();", 100);
waldo.disabled = "";
start.disabled = "disabled"
}
const touche = () => {
window.clearTimeout(lancement); // pour arreter le timer
result.innerHTML = " bravo tu as attrapé charlie en " + `${sec}` + "secondes et " + `${cent}${mill}` + "cent !!!!!";
result.style.bold
cent = 0;
mill = 0;
sec = 0;
document.getElementById('chrono').innerHTML = `0${sec}` + ":" + `0${cent}`
waldo.disabled = "disabled";
start.disabled = ""
waldo.style.top = `100px`;
}