-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinflip.html
56 lines (51 loc) · 1.37 KB
/
coinflip.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>coin flip game</title>
<style>
div {
display: inline;
}
.head_choice
</style>
</head>
<body>
<div
class="head_choice"
onclick="
playgame('head');
"
>
<img src="images/icons8-coin-48.png" alt="head" />
</div>
<div class="tail_choice" onclick=" playgame('tail');">
<img src="images/icons8-coin-48 (1).png" alt="tail" />
</div>
<p class="shows_selector"></p>
<script>
let score = JSON.parse(localStorage.getItem("score")) || {
wins: 0,
loose: 0,
};
function playgame(guess) {
const randomnumber = Math.random();
let result = "";
result = randomnumber < 0.5 ? "head" : "tail";
decison = guess === result ? "you win" : "you loose";
console.log(decison);
if (decison === "you win") {
score.wins++;
} else {
score.loose++;
}
console.log(`wins${score.wins} looses ${score.loose}`);
localStorage.setItem("score", JSON.stringify(score));
document.querySelector(
".shows_selector"
).innerHTML = `you choose ${guess} computer gets ${result}`;
}
</script>
</body>
</html>