-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
DedeJaelani2.js
73 lines (65 loc) · 1.65 KB
/
DedeJaelani2.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
const timeEl = document.getElementById("countdown-timer");
const word = document.getElementById("spellCheck");
const scoreEl = document.getElementById("scoreBoard");
//const remains constant throughout, let can be updated
let time = 11;
let score = 0;
scoreEl.innerHTML = score;
const words = ['sigh',
'tense',
'airplane',
'ball',
'pies',
'juice',
'warlike',
'bad',
'north',
'dependent',
'steer',
'silver',
'highfalutin',
'superficial',
'quince',
'eight',
'feeble',
'admit',
'drag',
'loving'
];
function getRandomElement () {
return words[Math.floor(Math.random() * words.length)];
}
function addWordToH3 () {
document.getElementById("word").innerHTML = getRandomElement();
}
var countdown = setInterval(updateTime,1000);
function updateTime () {
time--;
timeEl.innerHTML = time;
if(time == 0)
{
clearInterval(countdown);
document.getElementById("spellCheck").disabled = true;
document.getElementById("word").innerHTML = "TIME UP!";
}
}
addWordToH3();
function updateTime2() {
time += 2;
timeEl.innerHTML = time;
}
function updateScore () {
score += 1;
scoreEl.innerHTML = score;
}
//the main happening, here we add an event listener with an input to check out for any changes in the input text field. We pass element to the function so as we can target the input text field
word.addEventListener('input',function(element) {
const submission = element.target.value;
if(submission === document.getElementById("word").innerHTML) {
updateTime2();
addWordToH3();
// to clear the input area after word entered is correct
element.target.value = "";
updateScore();
}
});