Skip to content

Commit e8f8958

Browse files
committedNov 11, 2021
created second version initial pages
1 parent 46d9bfc commit e8f8958

File tree

11 files changed

+757
-0
lines changed

11 files changed

+757
-0
lines changed
 

‎.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
.HighScore{
6+
display: flex;
7+
justify-content: center;
8+
font-size: 2rem;
9+
color: rgb(0, 132, 255);
10+
padding: 20px;
11+
margin:20px;
12+
justify-content: space-around;
13+
}
14+
.center{
15+
display: flex;
16+
justify-content: center;
17+
padding: 1rem;
18+
}
19+
button{
20+
background-color: blue;
21+
color: white;
22+
font-size: 1.2rem;
23+
font-weight:bold;
24+
margin:1rem;
25+
padding: 1rem;
26+
border-style: solid;
27+
border-radius: 10px;
28+
}
29+
button:hover{
30+
background-color: rgb(58, 58, 240);
31+
color: white;
32+
}
33+
label{
34+
font-size: 1.2rem;
35+
font-family: cursive;
36+
padding-right: 1rem;
37+
}
38+
.highScoreContainer{
39+
border-style: solid;
40+
border-width: 2px;
41+
border-color: blueviolet;
42+
border-radius: 10px;
43+
margin: 10px;
44+
}
45+
.congratsBanner{
46+
border-style: solid;border-color: blue; border-radius: 5px; padding: 10px;
47+
width: 80%;
48+
left: 7%;
49+
position: relative;
50+
font-size: 1.5rem;
51+
}
52+
@keyframes blinker {
53+
50%{
54+
opacity: 0;
55+
}
56+
}
57+
</style>
58+
<meta charset="utf-8"/>
59+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
60+
61+
</head>
62+
<body style="background-color: rgb(174, 224, 240);">
63+
<div class="highScoreContainer">
64+
<label style="position: absolute; left: 10%;"> High Score</label>
65+
<div class="HighScore">
66+
<div id="user"> UserName: </div>
67+
<div id="score"> Score : </div>
68+
<div id="timing"> Timing :</div>
69+
</div>
70+
</div>
71+
<div class="highScoreContainer">
72+
<label style="position: absolute; left: 10%;"> Your Score</label>
73+
<div class="HighScore">
74+
<div id="UserScore"> Score : </div>
75+
<div id="UserTiming"> Timing :</div>
76+
</div>
77+
</div>
78+
<div class="UserHighScoreArea" style="display: none;">
79+
<div class="congratsBanner"><p style="font-family: Arial, Helvetica, sans-serif; font-size: 2.2rem; animation:blinker 1s linear infinite;" >Congratulations!</p> Your score is higher than the last highest score
80+
Enter your UserName to save your score as high score
81+
</div>
82+
<div class="center"><label>UserName : </label><input type="text" id="uname"/></div>
83+
<div class="center"><button id="btnSave">Save</button></div>
84+
</div>
85+
</body>
86+
<script src="End.js"></script>
87+
</html>

‎Quiz Application/QUIZ APP - V2/End.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const MAX_SCORE = JSON.parse(window.localStorage.getItem('score')) || [];
2+
const CURRENT_MAX_SCORE= +window.localStorage.getItem('currentScore');
3+
const Timing= window.localStorage.getItem('timing');
4+
const CURRENT_Timing= window.localStorage.getItem('currentTiming');
5+
6+
const ScoreElement=document.querySelector("#score");
7+
const TimingElement=document.querySelector("#timing");
8+
const UserScoreElement=document.querySelector("#UserScore");
9+
const UserTimingElement=document.querySelector("#UserTiming");
10+
const UserHighScoreAreaElement=document.querySelector(".UserHighScoreArea");
11+
const UserNameElement=document.querySelector("#uname");
12+
const UserNameHighScoreElement=document.querySelector("#user");
13+
const BtnSaveElement=document.querySelector("#btnSave");
14+
15+
16+
var s= isNaN(MAX_SCORE.score) ? 0 : +MAX_SCORE.score;
17+
var t=MAX_SCORE.timing=== undefined ? '00:00:00' : MAX_SCORE.timing;
18+
19+
ScoreElement.innerText="Score : " +s;
20+
TimingElement.innerText="Timing : " + t;
21+
UserNameHighScoreElement.innerText= MAX_SCORE.userName === undefined ? "UserName : "+ " ": "UserName : " +MAX_SCORE.userName;
22+
UserScoreElement.innerText="Score : " + CURRENT_MAX_SCORE;
23+
var tu= CURRENT_Timing===null ?0: CURRENT_Timing;
24+
UserTimingElement.innerText="Timing : " + tu;
25+
26+
let showAreaDoStuff= () =>{
27+
UserHighScoreAreaElement.setAttribute('style','display:block');
28+
29+
}
30+
//now we should replace the score if the user has scored high score than last high score
31+
let checkHighScore = () => {
32+
if(CURRENT_MAX_SCORE > s ){
33+
showAreaDoStuff();
34+
35+
}
36+
else if(CURRENT_MAX_SCORE === s && TimingFunc(CURRENT_Timing) < TimingFunc(t)){
37+
showAreaDoStuff();
38+
}
39+
};
40+
41+
let TimingFunc = (param) => {
42+
var hour=param.substr(0,2);
43+
var min=param.substr(3,2);
44+
var sec=param.substr(6,2);
45+
var date=new Date('2012','04','12',hour,min,sec);
46+
//console.log(date.getTime());
47+
return date.getTime();
48+
}
49+
50+
let btnSaveEventListener = () =>{
51+
let scoreObj={
52+
userName:UserNameElement.value,
53+
score:CURRENT_MAX_SCORE,
54+
timing:CURRENT_Timing
55+
56+
}
57+
//MAX_SCORE.userName=userName,MAX_SCORE.timing=timing,MAX_SCORE.score=score;
58+
window.localStorage.setItem('score',JSON.stringify(scoreObj));
59+
}
60+
checkHighScore();
61+
BtnSaveElement.addEventListener('click',btnSaveEventListener,false);
62+
63+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
* {
2+
background-color: #56a5eb;;
3+
margin:0;
4+
padding:0;
5+
}
6+
7+
.container{
8+
position: absolute;
9+
top: 50%;
10+
left: 50%;
11+
12+
}
13+
.box{
14+
border-style: solid;
15+
border-color: blue;
16+
border-radius: 10px;
17+
margin-top: 20%;
18+
padding:20px;
19+
box-shadow: 0 0.4rem 1.4rem 0 rgba(86, 185, 235, 0.5);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="PreQuiz.css"></link>
8+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
9+
<title>Quiz</title>
10+
</head>
11+
<body>
12+
<div id="container">
13+
<div id="row justify-content-center align-items-center">
14+
<form class="col-12">
15+
<div class="d-flex flex-column min-vh-100 justify-content-center align-items-center">
16+
<h1>Select Game Parameter</h1>
17+
<label for="numberOfQuestions" class="fw-bold p-2">Number of Questions :</label>
18+
<input id="numberOfQuestions" class="form-control p-2" type="number" min="10" max="50" title="numberOfQuestions">
19+
<label for="category" class="fw-bold p-2">Select area of quiz :</label>
20+
<select id="category" title="category" class="form-control p-2">
21+
<option>Select</option>
22+
<option value="18">Science: Computers</option>
23+
<option value="19">Science : Mathmatics</option>
24+
<option value="9">General Knowledge</option>
25+
</select>
26+
<label for="difficulty" class="fw-bold p-2">Select Difficulty :</label>
27+
<select id="difficulty" title="difficulty" class="form-control p-2">
28+
<option>Any difficulty</option>
29+
<option value="easy">Easy</option>
30+
<option value="medium">Medium</option>
31+
<option value="hard">Hard</option>
32+
</select>
33+
<div class="p-2">
34+
<input type="button" value="Bring It ON !!" class="btn btn-primary" onclick="startGame()">
35+
</div>
36+
</div>
37+
</form>
38+
39+
</div>
40+
41+
<!-- <div id="d-flex flex-column min-vh-100 justify-content-center align-items-center">
42+
<h1>Select Game Parameter</h1>
43+
<label>Select area of quiz :</label>
44+
<select id="category" title="category" class="form-select">
45+
<option>Select</option>
46+
<option value="18">Science: Computers</option>
47+
<option value="19">Science : Mathmatics</option>
48+
<option value="9">General Knowledge</option>
49+
</select>
50+
</div> -->
51+
<script src="PreQuiz.js"></script>
52+
</body>
53+
</html>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const QUESTIONELEMENT= document.getElementById("numberOfQuestions");
2+
const CATEGORYELEMENT=document.getElementById("category");
3+
const DIFFICULTYELEMENT=document.getElementById("difficulty");
4+
function startGame(){
5+
let number=QUESTIONELEMENT.value;
6+
let category=CATEGORYELEMENT.value;
7+
let difficult=DIFFICULTYELEMENT.value;
8+
9+
//console.log(number +" "+category+" "+difficult)
10+
11+
let urlForNextPage=`Quiz.html?amount=${encodeURIComponent(number)}&category=${encodeURIComponent(category)}&difficulty=${encodeURIComponent(difficult)}`;
12+
//let urlForNextPage=`Quiz.html`
13+
document.location.href=urlForNextPage;
14+
}
+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
.gameContent{
3+
border-style: solid;
4+
border-color: blue;
5+
border-radius: 10px;
6+
background-color: rgb(146, 214, 236);
7+
box-shadow: 0 0.4rem 1.4rem 0 rgba(86, 185, 235, 0.5);
8+
transform: translateY(-0.1rem);
9+
margin-top: 20%;
10+
padding:20px;
11+
}
12+
.gameTitle{
13+
font-size: 1.8rem;
14+
padding: 10px;
15+
text-align: center;
16+
}
17+
.question{
18+
margin-top: 10px;
19+
margin-bottom: 10px;
20+
font-size: 2.5rem;
21+
border-style: solid;
22+
border-color: rgb(107, 43, 226);
23+
border-radius: 10px;
24+
}
25+
.question p{
26+
padding-top: 5px;
27+
padding-left: 10px;
28+
color: rgba(3, 68, 245, 0.726);
29+
}
30+
.option{
31+
margin-bottom: 10px;
32+
padding:2px;
33+
border-style: solid;
34+
border-radius: 2px;
35+
border-color: rgb(46, 46, 245);
36+
border-radius: 8px;
37+
background-color:rgb(146, 214, 236); ;
38+
display: flex;
39+
}
40+
.option:hover{
41+
cursor: pointer ;
42+
box-shadow:0 0.4rem 1.4rem 1.4rem rgba(40, 172, 238, 0.5);
43+
transform: translateY(-0.1rem);
44+
transition: transform 150ms;
45+
}
46+
.choice-prefix{
47+
/* padding-top: 5px;
48+
padding-right: 15px; */
49+
/* padding-bottom: 1rem;
50+
padding-right: 1rem; */
51+
padding: 1rem 2rem ;
52+
background-color: #56a5eb;
53+
color: white;
54+
font-size: 2rem;
55+
font-weight: bold;
56+
border-radius: 8px;
57+
margin-top: 10px;
58+
}
59+
.answer{
60+
width: 100%;
61+
padding:1.5rem;
62+
color: rgba(3, 68, 245, 0.726);
63+
font-size: 2.5rem;
64+
font-weight: bold;
65+
}
66+
.correct{
67+
background-color: green;
68+
color: white;
69+
}
70+
.incorrect{
71+
background-color: red;
72+
color: white;
73+
}
74+
.progressContent{
75+
display: flex;
76+
position: absolute;
77+
margin-top: 30%;
78+
left: -50%;
79+
/* padding-right: 20px;
80+
padding-left: 20px; */
81+
}
82+
.progressText{
83+
color:#56a5eb;
84+
font-weight: bolder;
85+
font-size: 2.4rem;
86+
/* padding-right: 20px; */
87+
/* padding-left: 20px; */
88+
}
89+
.progressBar{
90+
border-style: solid;
91+
border-color: #1f8ae7;
92+
border-radius: 5px;
93+
width: 300px;
94+
height: 50px;
95+
display: flex;
96+
position:absolute;
97+
top:95%;
98+
}
99+
.progressBarFull{
100+
background-color: #469fec;
101+
}
102+
.scoreContent{
103+
display: flex;
104+
position: absolute;
105+
margin-top: 30%;
106+
}
107+
.scoreContent p{
108+
color:#56a5eb;
109+
font-weight: bolder;
110+
font-size: 2.4rem;
111+
}
112+
.timerRegion{
113+
color:#56a5eb;
114+
font-weight: bolder;
115+
font-size: 2.4rem;
116+
padding-left: 30%;
117+
}
118+
.questionTimer{
119+
color:#56a5eb;
120+
font-weight: bolder;
121+
font-size: 2.4rem;
122+
padding-left: 30%;
123+
top: 20%;
124+
left: 20%;
125+
display: flex;
126+
position: relative;
127+
}
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<title> Quiz App</title>
9+
<link rel="stylesheet" type="text/css" href="Quiz.css">
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
11+
</head>
12+
<body>
13+
<div class="container">
14+
15+
<div class="row">
16+
<div class="col-md-2">
17+
<div class="progressContent">
18+
<div class="progressText">
19+
Question 1 of 1
20+
</div>
21+
<div class="progressBar">
22+
<div class="progressBarFull"></div>
23+
</div>
24+
</div>
25+
</div>
26+
<div class="col-md-8">
27+
<div class="timerRegion">
28+
<p> Timer : </p>
29+
</div>
30+
<!-- <div class="questionTimer">
31+
<p> Question Timer : </p>
32+
</div> -->
33+
<div class="gameContent">
34+
<div id="game" class="mainGame">
35+
<div class="gameTitle">Computer Quiz</div>
36+
<div class="question">
37+
<p>Question will appear here</p>
38+
</div>
39+
40+
<div class="option"><p class="choice-prefix">A</p><p class="answer" id="opt1"></p></div>
41+
<div class="option"><p class="choice-prefix">B</p><p class="answer" id="opt2"></p></div>
42+
<div class="option"><p class="choice-prefix">C</p><p class="answer" id="opt3"></p></div>
43+
<div class="option"><p class="choice-prefix">D</p><p class="answer" id="opt4"></p></div>
44+
</div>
45+
</div>
46+
</div>
47+
<div class="col-md-2">
48+
<div class="scoreContent">
49+
<p>Score 0</p>
50+
</div>
51+
</div>
52+
</div>
53+
</div>
54+
<!-- <div class="masterTimer">
55+
<span></span>
56+
</div>
57+
<div class="progressContent">
58+
<div class="hud"> -->
59+
<!-- <div class="progressText"> Question </div>
60+
<div class="pbar">
61+
<div class="progressBar"></div>
62+
</div> -->
63+
<!-- <div class="scoreText">Score : 0</div>
64+
</div> -->
65+
<!-- </div> -->
66+
<!-- <div class="mainContent"> -->
67+
<!-- <div id="game" class="justify-center flex-column">
68+
<div class="Heading">Computer Quiz</div>
69+
<div class="question">
70+
<p><Question will appear here --></p>
71+
<!-- </div> -->
72+
<!-- <div class="option"> <input type="radio" name="option" class="answer option1" id="1"><span id="opt1" style="padding-left: 10px; color: white;"></span></div>
73+
<div class="option"> <input type="radio" name="option" class="answer option2" id="2"><span id="opt2" style="padding-left: 10px; color:white;"></span></div>
74+
<div class="option"> <input type="radio" name="option" class="answer option3" id="3"><span id="opt3" style="padding-left: 10px; color: white;"></span></div>
75+
<div class="option"> <input type="radio" name="option" class="answer option4" id="4"><span id="opt4" style="padding-left: 10px; color:white"></span></div> -->
76+
77+
<!-- new style -->
78+
79+
<!-- <br> -->
80+
<!-- <button id="lockAnswer">Lock Answer</button>
81+
<button id="nextQuestion">Next Question</button> -->
82+
<!-- </div> -->
83+
<!-- </div> -->
84+
85+
86+
<script src="Quiz.js"></script>
87+
<!-- jQuery library -->
88+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
89+
90+
<!-- Latest compiled JavaScript -->
91+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
92+
</body>
93+
</html>
+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
//#region QuestionsStatic
2+
let questionsArray=[
3+
{
4+
"question": "Inside which HTML element do we put the JavaScript??",
5+
"choice1": "<script>",
6+
"choice2": "<javascript>",
7+
"choice3": "<js>",
8+
"choice4": "<scripting>",
9+
"answer": 1
10+
},
11+
{
12+
"question": "What is the correct syntax for referring to an external script called 'xxx.js'?",
13+
"choice1": "<script href='xxx.js'>",
14+
"choice2": "<script name='xxx.js'>",
15+
"choice3": "<script src='xxx.js'>",
16+
"choice4": "<script file='xxx.js'>",
17+
"answer": 3
18+
},
19+
{
20+
"question": " How do you write 'Hello World' in an alert box?",
21+
"choice1": "msgBox('Hello World');",
22+
"choice2": "alertBox('Hello World');",
23+
"choice3": "msg('Hello World');",
24+
"choice4": "alert('Hello World');",
25+
"answer": 4
26+
},
27+
{
28+
29+
"question": "What does GHz stand for?",
30+
"answer": 4,
31+
"choice4":"Gigahertz",
32+
"choice1":"Gigahotz",
33+
"choice2":"Gigahetz",
34+
"choice3":"Gigahatz"
35+
},
36+
{
37+
"question": "What amount of bits commonly equals one byte?",
38+
"answer": 3,
39+
"choice4":"64",
40+
"choice1":"1",
41+
"choice2":"2",
42+
"choice3":"8"
43+
},
44+
{
45+
"question": "In the programming language Java, which of these keywords would you put on a variable to make sure it doesn't get modified?",
46+
"answer": 4,
47+
"choice4":"Final",
48+
"choice1":"Static",
49+
"choice2":"Private",
50+
"choice3":"Public"
51+
52+
},
53+
{
54+
"question": "Which data structure does FILO apply to?",
55+
"answer": 1,
56+
"choice4":"stack",
57+
"choice1":"queue",
58+
"choice2":"heap",
59+
"choice3":"tree"
60+
}
61+
];
62+
63+
//#endregion
64+
65+
// how many question are there in the game
66+
const MAX_QUESTION=questionsArray.length;
67+
const SCORE_BONUS=10;
68+
const questionElement=document.querySelector(".question p");
69+
const option1Element=document.querySelector("#opt1");
70+
const option2Element=document.querySelector("#opt2");
71+
const option3Element=document.querySelector("#opt3");
72+
const option4Element=document.querySelector("#opt4");
73+
const progressBarElement=document.querySelector(".progressBarFull");
74+
const progressTextElement=document.querySelector(".progressText");
75+
const scoreTextElement=document.querySelector(".scoreContent p");
76+
const timerPara=document.querySelector(".timerRegion p");
77+
//const questionTimerPara=document.querySelector(".questionTimer p");
78+
79+
var lastQuestionAnswered;
80+
var score;
81+
var timer=[0, 0, 0, 0];
82+
var questionTimer=[0,0,0];
83+
var timerIsRunning=false;
84+
var intervalQuestion;
85+
var intervalTimer;
86+
var intervalSingleQuestion;
87+
var timeoutSingleQuestion;
88+
//when window loads initialize the game
89+
90+
lastQuestionAnswered=-1;
91+
score=0;
92+
startGame();
93+
94+
//start the game
95+
function startGame(){
96+
window.localStorage.removeItem('currentScore');
97+
window.localStorage.removeItem('currentTiming');
98+
LoadNextQuestion();
99+
if(!timerIsRunning){
100+
timerIsRunning=true;
101+
intervalTimer=setInterval(startTimer,10);
102+
}
103+
//intervalSingleQuestion=setInterval(questionTimerFun,10);
104+
}
105+
106+
//setTimeout(LoadNextQuestion,5000);
107+
108+
function resetQuestionTimer() {
109+
var questionTimer=[0,0,0];
110+
clearInterval(intervalSingleQuestion); //clear the question interval first
111+
intervalSingleQuestion=setInterval(questionTimerFun,10); // set it back. so that clock starts from zero -TODO
112+
LoadNextQuestion();
113+
}
114+
//this is global timer
115+
function startTimer() {
116+
//console.log("starttimer"+ timer[3] +" "+timer[0]);
117+
var currentTime= padLeadingZero(timer[0]) +":"+ padLeadingZero(timer[1]) +":"+ padLeadingZero(timer[2]) ;
118+
timerPara.innerText=" Timer : "+currentTime;
119+
timer[3]++;
120+
121+
timer[0]=Math.floor((timer[3]/100)/60);
122+
timer[1] = Math.floor((timer[3]/100) - (timer[0] * 60));
123+
timer[2] = Math.floor(timer[3] - (timer[1] * 100) - (timer[0] * 6000));
124+
125+
}
126+
127+
//this is for particular question
128+
function questionTimerFun() {
129+
//question timer
130+
//console.log("starttimer"+ timer[1] +" "+timer[0]+" "+timer[2]);
131+
var currentQuestionTime = padLeadingZero(questionTimer[1])
132+
133+
questionTimerPara.innerText=" Question Timer : "+currentQuestionTime;
134+
questionTimer[2]++;
135+
questionTimer[0]=Math.floor((questionTimer[2]/100)/60);
136+
questionTimer[1] = Math.floor((questionTimer[2]/100) - (questionTimer[0] * 60));
137+
//questionTimer[1]=Math.floor(timer[2] - (timer[0] * 6000));
138+
}
139+
140+
function padLeadingZero(params) {
141+
if(+params<=9)
142+
return "0"+params;
143+
else
144+
return params;
145+
}
146+
147+
//load the next question
148+
function LoadNextQuestion(){
149+
lastQuestionAnswered++;
150+
clearInterval(intervalQuestion);
151+
//console.log("LoadnextQuestion "+lastQuestionAnswered+" "+ ((+lastQuestionAnswered+1)/MAX_QUESTION)*100);
152+
progressBarElement.style.width=`${((+lastQuestionAnswered)/MAX_QUESTION)*100}%`;
153+
progressTextElement.innerText=` Question ${lastQuestionAnswered+1} of ${MAX_QUESTION}`;
154+
if(lastQuestionAnswered < MAX_QUESTION){
155+
156+
questionElement.innerText=questionsArray[lastQuestionAnswered].question;
157+
option1Element.innerText=questionsArray[lastQuestionAnswered].choice1;
158+
option2Element.innerText=questionsArray[lastQuestionAnswered].choice2;
159+
option3Element.innerText=questionsArray[lastQuestionAnswered].choice3;
160+
option4Element.innerText=questionsArray[lastQuestionAnswered].choice4;
161+
}
162+
163+
}
164+
165+
//check the answer
166+
function checkAnswer(event){
167+
168+
let correctAnswer=questionsArray[lastQuestionAnswered].answer; //this is correct answer
169+
170+
let userAns=this.id.substr(-1); //this answer user has given
171+
const d=event.target;
172+
173+
if(+userAns === correctAnswer){
174+
d.setAttribute("style","color:white;");
175+
d.parentElement.setAttribute("style","background-color :green; color:white;");
176+
score+=SCORE_BONUS;
177+
scoreTextElement.innerText=` Score : ${score}`
178+
}
179+
else{
180+
d.setAttribute("style","color:white;");
181+
d.parentElement.setAttribute("style","background-color :red; ");
182+
}
183+
184+
if(lastQuestionAnswered<MAX_QUESTION-1){
185+
intervalQuestion= setInterval(function(){
186+
d.removeAttribute("style");
187+
d.parentElement.removeAttribute("style");
188+
LoadNextQuestion();
189+
},500);
190+
}
191+
if(lastQuestionAnswered==MAX_QUESTION-1){
192+
//console.log("checkAnswer "+lastQuestionAnswered);
193+
progressBarElement.style.width=`${((+lastQuestionAnswered+1)/MAX_QUESTION)*100}%`;
194+
progressTextElement.innerText=` Question ${lastQuestionAnswered+1} of ${MAX_QUESTION}`;
195+
clearInterval(intervalTimer);
196+
setInterval(function(){
197+
document.location.href="End.html";
198+
window.localStorage.setItem('currentScore',score);
199+
//console.log(timerPara.innerText);
200+
window.localStorage.setItem('currentTiming',timerPara.innerText.substr(8,timerPara.innerText.length));
201+
},1000);
202+
}
203+
//lastQuestionAnswered++;
204+
205+
}
206+
207+
//setInterval(LoadNextQuestion,5000);
208+
209+
//************* event binding section *********************/
210+
//bind the function to click event
211+
option1Element.addEventListener("click",checkAnswer,false);
212+
option2Element.addEventListener("click",checkAnswer,false);
213+
option3Element.addEventListener("click",checkAnswer,false);
214+
option4Element.addEventListener("click",checkAnswer,false);
215+
216+
217+
218+
219+
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
* {
2+
background-color: #56a5eb;;
3+
margin:0;
4+
padding:0;
5+
}
6+
h1{
7+
display:flex;
8+
justify-content: center;
9+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
10+
padding: 3rem;
11+
12+
}
13+
.message{
14+
border-style: solid;
15+
border-width: 2px;
16+
border-color: blue;
17+
border-radius: 10px;
18+
position: absolute;
19+
justify-content: center;
20+
width: 40%;
21+
padding: 10px;
22+
left: 30%;
23+
24+
}
25+
.message p{
26+
font-size: large;
27+
font-weight: initial;
28+
font-family: "Lucida Console", Courier, monospace;
29+
}
30+
p >strong{
31+
font-size: 3rem;
32+
font-family: cursive;
33+
}
34+
.container{
35+
position: absolute;
36+
top: 50%;
37+
left: 40%;
38+
}
39+
a{
40+
font-size: 1.2rem;
41+
font-weight:bold;
42+
border-style: solid;
43+
border-width: 2px;
44+
border-radius: 5px;
45+
text-decoration: none;
46+
padding: 1rem;
47+
margin-left: 10px;
48+
}
49+
a:hover{
50+
background-color: blue;
51+
color:white;
52+
font-style: italic;
53+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<link rel="stylesheet" href="Start.css"/>
7+
<script>
8+
window.localStorage.removeItem('currentScore');
9+
window.localStorage.removeItem('currentTiming');
10+
11+
</script>
12+
13+
</head>
14+
<body>
15+
<h1>Welcome to Quiz!</h1>
16+
<div class="message"><p> The question will be automatically change once you answer the question. The fastest and with max score will
17+
be considered as higest score. <br>
18+
<strong>Best of Luck !</strong>
19+
</p></div>
20+
<div class="container">
21+
<a href="Quiz.html">Game</a>
22+
<a href="End.html">High Score</a>
23+
</div>
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.