-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
82 lines (66 loc) · 2.22 KB
/
Copy pathapp.js
File metadata and controls
82 lines (66 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
76
77
78
79
80
81
82
const select=document.getElementById('opt');
const time=document.getElementById('time');
const score=document.getElementById('score');
const word=document.getElementById('word');
const game=document.getElementById('game');
const failed=document.getElementById('failed');
const input=document.getElementById('input-word');
const reload=document.getElementById('Reload');
const failed_score=document.getElementById('failed-score');
let difficulty='Easy';
let second=18;
let plusTime=4;
let index=0,score_val=0;
let words_list=['pouya','bad','structure','python','ruler','internal','fgsdfh','qsdfkjer','lpoiwefb','qwedfvdsb'
,'bzperjq','qlduanbvd','turtle','uevzlkfda','dvajhwedvkj','asdwev','tavxntowfg'];
word.innerText=words_list[index];
score.innerText=`score: ${score_val}`;
function starting(){
let interTime=setInterval(function(){
second--;
time.innerText=`Time Left: ${second}`;
if(second===0){
game.style.display="none";
failed.style.display="block";
failed_score.innerText=`your score is ${score_val}`;
clearInterval(interTime);
}
},1000);
}
function updateDom(){
index++;score_val++;
if(index==words_list.length-1){
index=0;
}
second+=plusTime;
word.innerText=words_list[index];
score.innerText=`score: ${score_val}`;
}
select.addEventListener('change',function(){
difficulty=select.value;
if(difficulty=='Hard') {second=5;plusTime=2;};
if(difficulty=='Medium') {second=10;plusTime=3;};
if(difficulty=='Easy') {second=18;plusTime=4;};
time.innerText=`Time Left: ${second}`;
});
input.addEventListener('input',function(e){
if(input.value==word.innerText){
input.value='';
updateDom();
}
});
reload.addEventListener('click',function(){
game.style.display="block";
failed.style.display="none";
score_val=0;
index=0;
input.value='';
score.innerText=`score: ${score_val}`;
difficulty=select.value;
if(difficulty=='Hard') {second=5;plusTime=2;};
if(difficulty=='Medium') {second=10;plusTime=3;};
if(difficulty=='Easy') {second=18;plusTime=4;};
time.innerText=`Time Left: ${second}`;
starting();
});
window.addEventListener('load',starting);