Skip to content

Commit be82cdb

Browse files
committed
Typing Game Using HTML, CSS and JavaScript
1 parent 1ee722c commit be82cdb

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

‎86. Typing Game/app.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
constmain=document.querySelector(".main");
2+
consttypeArea=document.querySelector(".typingArea");
3+
constbtn=document.querySelector(".btn");
4+
5+
constwords=[
6+
"A day in the life of programmer",
7+
"What is JavaScript?",
8+
"What is React?",
9+
"What is Programming Language?",
10+
"What's your name?",
11+
"Where are you from?",
12+
"This is just random word",
13+
"What is Remix.js?",
14+
"New Technologies",
15+
"Is programming hard?",
16+
"Why do you wanna become a programmer?",
17+
"Which programming language you like the most?",
18+
"What is Golang? and why do you wanna learn it?",
19+
"What is CSS",
20+
];
21+
22+
constgame={
23+
start: 0,
24+
end: 0,
25+
user: "",
26+
arrText: "",
27+
};
28+
29+
btn.addEventListener("click",()=>{
30+
if(btn.textContent==="Start"){
31+
play();
32+
typeArea.value="";
33+
typeArea.disabled=false;
34+
}elseif(btn.textContent==="Done"){
35+
typeArea.disabled=true;
36+
main.style.borderColor="white";
37+
end();
38+
}
39+
});
40+
41+
functionplay(){
42+
letrandText=Math.floor(Math.random()*words.length);
43+
main.textContent=words[randText];
44+
game.arrText=words[randText];
45+
main.style.borderColor="#c8c8c8";
46+
btn.textContent="Done";
47+
constduration=newDate();
48+
game.start=duration.getTime();// unix timestamp
49+
}
50+
51+
functionend(){
52+
constduration=newDate();
53+
game.end=duration.getTime();
54+
consttotalTime=(game.end-game.start)/1000;
55+
game.user=typeArea.value;
56+
constcorrect=results();
57+
main.style.borderColor="white";
58+
main.innerHTML=`Time: ${totalTime} Score: ${correct.score} out of ${correct.total}`;
59+
btn.textContent="Start";
60+
}
61+
62+
functionresults(){
63+
letvalueOne=game.arrText.split(" ");
64+
letvalueTwo=game.user.split(" ");
65+
letscore=0;
66+
valueOne.forEach((word,idx)=>{
67+
if(word===valueTwo[idx]){
68+
score++;
69+
}
70+
});
71+
72+
return{ score,total: valueOne.length};
73+
}

‎86. Typing Game/index.html‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<htmllang="en">
2+
<head>
3+
<metacharset="UTF-8" />
4+
<metahttp-equiv="X-UA-Compatible" content="IE=edge" />
5+
<metaname="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Typing Challenge</title>
7+
<linkrel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<divclass="container">
11+
<divclass="main"></div>
12+
<textareaname="words" class="typingArea"></textarea>
13+
<br/>
14+
<buttonclass="btn">Start</button>
15+
</div>
16+
<scriptsrc="app.js"></script>
17+
</body>
18+
</html>

‎86. Typing Game/style.css‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
body{
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
text-align: center;
6+
}
7+
8+
.container{
9+
width:70%;
10+
padding:10px;
11+
}
12+
13+
.main{
14+
text-align: center;
15+
padding:10px;
16+
font-size:2em;
17+
border:3px solid white;
18+
}
19+
20+
.typingArea{
21+
width:100%;
22+
height:350px;
23+
margin-top:20px;
24+
}
25+
26+
.btn{
27+
width:20%;
28+
outline: none;
29+
border: none;
30+
font-size:2em;
31+
padding:10px;
32+
color: white;
33+
background-color: blueviolet;
34+
margin-top:20px;
35+
}

0 commit comments

Comments
(0)