-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
57 lines (48 loc) · 1.4 KB
/
index.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
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Odd-Even Game!</title>
<style>
div {
text-align: center;
width: 440px;
margin: 0 auto;
}
button {
padding: 20px;
font-size: 28px;
font-weight: bold;
}
</style>
</head>
<body>
<div>
<p>Choose a number between 1 and 2.<br>
The computer will also choose a number randomly.<br>
If the sum of your and computer's number is EVEN,<br>
then you win, and if it's ODD then you lose.<br><br>
Choose from below
</p>
<button onclick="giveOne()">1</button>
<button onclick="giveTow()">2</button>
<h2 id="winner"></h2>
</div>
</body>
<script>
let info = document.querySelector("#winner");
function giveOne() { calc(1) };
function giveTow() { calc(2) };
function calc(player) {
const computer = (Math.floor(Math.random() * 2) + 1);
let message = `You : ${player}\nComputer: ${computer}\n`;
if ((player + computer) % 2 === 0) {
message += `\nYou win!`
} else {
message += `\nYou lose`
}
info.innerText = message;
}
</script>
</html>