-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (25 loc) · 1.16 KB
/
script.js
File metadata and controls
33 lines (25 loc) · 1.16 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
const words = ["damn son","gyatt crusader","cheeks","ballvinder","deepinder","hardick","richard hiscock","sujeet","kuljeet","balljeet","harry bolz","roti should be round","hello from microsoft support","touch some grass","go shower","mango chutney","chai masala"];
const wordDisplay = document.getElementById("word-display");
const inputField = document.getElementById("input-field");
const result = document.getElementById("result");
const startGame = () => {
targetword = words[Math.floor(Math.random()*words.length)];
wordDisplay.textContent = `" ${targetword}"` ;
inputField.value="";
inputField.className ="";
result.textContent="";
startTime = Date.now();
};
inputField.addEventListener("input",()=>{
if (inputField.value ===targetword){
let elapsedTime=((Date.now()-startTime)/1000).toFixed(2);
result.textContent=`You took ${elapsedTime} seconds, you 🤡`;
inputField.classList.add("correct");
setTimeout(startGame,1500);
}else if (!targetword.startsWith(inputField.value)){
inputField.classList.add("wrong");
} else {
inputField.classList.remove("wrong");
}
});
startGame();