-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpi.html
More file actions
75 lines (64 loc) · 1.48 KB
/
pi.html
File metadata and controls
75 lines (64 loc) · 1.48 KB
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
<!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>PI</title>
<style>
html {
background-color: #0D4B76;
overflow: hidden;
}
body {
margin: 0;
}
#picontainer {
color: white;
font: 15rem Arial;
margin: 0 auto;
width: 100%;
overflow: hidden;
direction: rtl;
text-overflow: clip;
}
#pi {
text-align: right;
user-select: none;
}
</style>
</head>
<body>
<div id="picontainer">
<label id="pi">3.141</label><br>
score: <label id="score">0</label>
</div>
</body>
<script>
const piLabel = document.getElementById("pi");
const scoreLabel = document.getElementById("score");
const pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384";
let position = 5, correct = true, score = 0;
window.addEventListener("keypress", ev => {
if (ev.key === "r") {
piLabel.innerText = "3.141";
scoreLabel.innerText = "0";
position = 5;
correct = true;
return;
}
if (parseInt(ev.key) === NaN)
return
if (ev.key !== pi[position]) {
correct = false;
return;
}
piLabel.innerText += ev.key;
position++;
if (correct) {
score++;
scoreLabel.innerText = score;
}
});
</script>
</html>