-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (65 loc) · 2.22 KB
/
Copy pathscript.js
File metadata and controls
78 lines (65 loc) · 2.22 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
'use strict';
const check = document.querySelector('.check')
const message = document.querySelector('.message')
const invoerWaarde = document.querySelector('.guess')
const vraagteken = document.querySelector('.number')
const scoreWeergave = document.querySelector('.score')
const HighScoreWeergave = document.querySelector('.highscore')
const again = document.querySelector('.again')
let teRadenGetal
let score
let laatsteGetal = -1
let highScore = 0
let defaultMessage = message.textContent
let defaultTeken = vraagteken.textContent
invoerWaarde.addEventListener('click', function (e) {
console.log(e)
if (e.clientX < 260) invoerWaarde.value = ''
})
const startSpel = () => {
let kiesNieuwGetal = () => Math.round(Math.random() * 19)
teRadenGetal = kiesNieuwGetal()
score = 20
scoreWeergave.textContent = score
check.addEventListener('click', invoerChecken)
again.removeEventListener('click', playItAgainSam)
invoerWaarde.value = ''
message.textContent = defaultMessage
vraagteken.classList.remove('AchtergrondGroen')
vraagteken.textContent = defaultTeken
}
const invoerChecken = () => {
if (invoerWaarde.value == "") {
message.textContent = "vul wel iets (zinnigs) in"
return
}
if (Number(invoerWaarde.value) == laatsteGetal) {
message.textContent = "Wel wat anders invullen!"
return
}
if (Number(invoerWaarde.value < 1 || Number(invoerWaarde.value) > 20)) {
message.textContent = "Tussen de 1 en 20 pls.."
return
}
laatsteGetal = Number(invoerWaarde.value)
if (teRadenGetal == Number(invoerWaarde.value)) {
message.textContent = 'joho bier'
vraagteken.textContent = teRadenGetal
vraagteken.classList.add('AchtergrondGroen')
check.removeEventListener('click', invoerChecken)
if (highScore < score) {
highScore = score;
HighScoreWeergave.textContent = highScore
}
again.addEventListener('click', playItAgainSam)
return
}
else {
message.textContent = Number(invoerWaarde.value) < teRadenGetal ? 'te laag' : 'te hoog'
scoreWeergave.textContent = --score
}
}
const playItAgainSam = () => {
startSpel()
}
startSpel()