Skip to content

Commit f74d4d2

Browse files
authored
Merge pull request #167 from jyothi-k-g/main
Added online quiz portal #122
2 parents e7c56e1 + 9c1062a commit f74d4d2

File tree

7 files changed

+740
-0
lines changed

7 files changed

+740
-0
lines changed

Index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@
7272
| [Tribute Page](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/TRIBUTE%20PAGE) | This is a tribute web page for covid warriors. Have built it using HTML, CSS, JAVASCRIPT. |
7373
| [BMI Calculator (Flask)](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/BMI%20Calculator%20(Flask))|This is a simple BMI calculator built using HTML, CSS, Python and Flask framework.|
7474
| [Basic Contact Form](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/Basic-Contact-Form) | A basic contact form having reset and send button. |
75+
| [Online quiz portal](https://github.com/Ayushparikh-code/Web-dev-mini-projects/tree/main/online%20quiz%20portal) | An online portal in which an individual can attend the quiz and view the result automatically |

online quiz portal/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Online quiz portal
2+
3+
## Description
4+
It is an online portal in which one can attend the quiz online and view the results immeadiately after completing the quiz
5+
6+
## Use of this Project
7+
Using this portal one can attend the quiz virtually and view the scores in real time
8+
9+
## Stacks Used
10+
* JavaScript
11+
* HTML
12+
* CSS
13+
14+
## How to set up project
15+
Download the zip file and copy all the files in the single folder. Open the folder in visual studio code and copy the path of the index file and paste it in the search box of google chrome to view the output.
16+
17+
## ScreenShot
18+
19+
<img src="https://github.com/jyothi-k-g/online-quiz-poral/blob/main/images/s1.png" />
20+

online quiz portal/index.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Online quiz portal</title>
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
9+
</head>
10+
<body>
11+
<!-- start Quiz button -->
12+
<div class="start_btn"><button>Start Quiz</button></div>
13+
14+
<!-- Info Box -->
15+
<div class="info_box">
16+
<div class="info-title"><span>Rules for the quiz
17+
18+
</span></div>
19+
<div class="info-list">
20+
<div class="info">1. Once you select your answer, it can't be undone.</div>
21+
<div class="info">2. You will have only 15 seconds per each question.</div>
22+
<div class="info">3. You'll get points on the basis of your correct answers.</div>
23+
</div>
24+
<div class="buttons">
25+
<button class="quit">Exit Quiz</button>
26+
<button class="restart">Continue</button>
27+
</div>
28+
</div>
29+
30+
<!-- Quiz Box -->
31+
<div class="quiz_box">
32+
<header>
33+
<div class="title">Online quiz portal</div>
34+
<div class="timer">
35+
<div class="time_left_txt">Time Left</div>
36+
<div class="timer_sec">15</div>
37+
</div>
38+
<div class="time_line"></div>
39+
</header>
40+
<section>
41+
<div class="que_text">
42+
</div>
43+
<div class="option_list">
44+
</div>
45+
</section>
46+
47+
<footer>
48+
<div class="total_que">
49+
<!-- Here I've inserted Question Count Number from JavaScript -->
50+
</div>
51+
<button class="next_btn">Next Question</button>
52+
</footer>
53+
</div>
54+
55+
<!-- Result Box -->
56+
<div class="result_box">
57+
<div class="icon">
58+
<i class="fas fa-crown"></i>
59+
</div>
60+
<div class="complete_text">You've completed the Quiz!</div>
61+
<div class="score_text">
62+
<!-- Here I've inserted Score Result from JavaScript -->
63+
</div>
64+
<div class="buttons">
65+
<button class="restart">Replay Quiz</button>
66+
<button class="quit">Quit Quiz</button>
67+
</div>
68+
</div>
69+
70+
71+
<script src="question.js"></script>
72+
73+
<script src="script.js"></script>
74+
75+
</body>
76+
</html>

online quiz portal/question.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
let questions = [
2+
{
3+
numb: 1,
4+
question: "Regression testing is primarily related to",
5+
answer: "Functional testing",
6+
options: [
7+
"Maintenance testing",
8+
"Data flow testing",
9+
"Functional testing",
10+
"Development testing"
11+
]
12+
},
13+
{
14+
numb: 2,
15+
question: "What is the defect rate for Six sigma",
16+
answer: "3.4 defects per million lines of code",
17+
options: [
18+
"3.0 defects per million lines of code",
19+
"3.4 defects per million lines of code",
20+
"1.4 defects per million lines of code",
21+
"1.0 defect per million lines of code"
22+
]
23+
},
24+
{
25+
numb: 3,
26+
question: "Of the following sort algorithms, which has execution time that is least dependent on initial ordering of the input ?",
27+
answer: "Merge sort",
28+
options: [
29+
"Selection sort",
30+
"Insertion sort",
31+
"Quick sort",
32+
"Merge sort"
33+
]
34+
},
35+
{
36+
numb: 4,
37+
question: "The domain of the function log( log sin(x) ) is",
38+
answer: "Empty set",
39+
options: [
40+
"0 < x < π",
41+
"Empty set",
42+
"0 < x < π",
43+
"2nπ < x < (2n + 1) π , for n in N "
44+
]
45+
},
46+
47+
];
48+

online quiz portal/screenshot/s1.png

45.2 KB
Loading

online quiz portal/script.js

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
//selecting all required elements
2+
const start_btn = document.querySelector(".start_btn button");
3+
const info_box = document.querySelector(".info_box");
4+
const exit_btn = info_box.querySelector(".buttons .quit");
5+
const continue_btn = info_box.querySelector(".buttons .restart");
6+
const quiz_box = document.querySelector(".quiz_box");
7+
const result_box = document.querySelector(".result_box");
8+
const option_list = document.querySelector(".option_list");
9+
const time_line = document.querySelector("header .time_line");
10+
const timeText = document.querySelector(".timer .time_left_txt");
11+
const timeCount = document.querySelector(".timer .timer_sec");
12+
13+
// if startQuiz button clicked
14+
start_btn.onclick = ()=>{
15+
info_box.classList.add("activeInfo"); //show info box
16+
}
17+
18+
// if exitQuiz button clicked
19+
exit_btn.onclick = ()=>{
20+
info_box.classList.remove("activeInfo"); //hide info box
21+
}
22+
23+
// if continueQuiz button clicked
24+
continue_btn.onclick = ()=>{
25+
info_box.classList.remove("activeInfo"); //hide info box
26+
quiz_box.classList.add("activeQuiz"); //show quiz box
27+
showQuetions(0); //calling showQestions function
28+
queCounter(1); //passing 1 parameter to queCounter
29+
startTimer(15); //calling startTimer function
30+
startTimerLine(0); //calling startTimerLine function
31+
}
32+
33+
let timeValue = 15;
34+
let que_count = 0;
35+
let que_numb = 1;
36+
let userScore = 0;
37+
let counter;
38+
let counterLine;
39+
let widthValue = 0;
40+
41+
const restart_quiz = result_box.querySelector(".buttons .restart");
42+
const quit_quiz = result_box.querySelector(".buttons .quit");
43+
44+
// if restartQuiz button clicked
45+
restart_quiz.onclick = ()=>{
46+
quiz_box.classList.add("activeQuiz"); //show quiz box
47+
result_box.classList.remove("activeResult"); //hide result box
48+
timeValue = 15;
49+
que_count = 0;
50+
que_numb = 1;
51+
userScore = 0;
52+
widthValue = 0;
53+
showQuetions(que_count); //calling showQestions function
54+
queCounter(que_numb); //passing que_numb value to queCounter
55+
clearInterval(counter); //clear counter
56+
clearInterval(counterLine); //clear counterLine
57+
startTimer(timeValue); //calling startTimer function
58+
startTimerLine(widthValue); //calling startTimerLine function
59+
timeText.textContent = "Time Left"; //change the text of timeText to Time Left
60+
next_btn.classList.remove("show"); //hide the next button
61+
}
62+
63+
// if quitQuiz button clicked
64+
quit_quiz.onclick = ()=>{
65+
window.location.reload(); //reload the current window
66+
}
67+
68+
const next_btn = document.querySelector("footer .next_btn");
69+
const bottom_ques_counter = document.querySelector("footer .total_que");
70+
71+
// if Next Que button clicked
72+
next_btn.onclick = ()=>{
73+
if(que_count < questions.length - 1){ //if question count is less than total question length
74+
que_count++; //increment the que_count value
75+
que_numb++; //increment the que_numb value
76+
showQuetions(que_count); //calling showQestions function
77+
queCounter(que_numb); //passing que_numb value to queCounter
78+
clearInterval(counter); //clear counter
79+
clearInterval(counterLine); //clear counterLine
80+
startTimer(timeValue); //calling startTimer function
81+
startTimerLine(widthValue); //calling startTimerLine function
82+
timeText.textContent = "Time Left"; //change the timeText to Time Left
83+
next_btn.classList.remove("show"); //hide the next button
84+
}else{
85+
clearInterval(counter); //clear counter
86+
clearInterval(counterLine); //clear counterLine
87+
showResult(); //calling showResult function
88+
}
89+
}
90+
91+
// getting questions and options from array
92+
function showQuetions(index){
93+
const que_text = document.querySelector(".que_text");
94+
95+
//creating a new span and div tag for question and option and passing the value using array index
96+
let que_tag = '<span>'+ questions[index].numb + ". " + questions[index].question +'</span>';
97+
let option_tag = '<div class="option"><span>'+ questions[index].options[0] +'</span></div>'
98+
+ '<div class="option"><span>'+ questions[index].options[1] +'</span></div>'
99+
+ '<div class="option"><span>'+ questions[index].options[2] +'</span></div>'
100+
+ '<div class="option"><span>'+ questions[index].options[3] +'</span></div>';
101+
que_text.innerHTML = que_tag; //adding new span tag inside que_tag
102+
option_list.innerHTML = option_tag; //adding new div tag inside option_tag
103+
104+
const option = option_list.querySelectorAll(".option");
105+
106+
// set onclick attribute to all available options
107+
for(i=0; i < option.length; i++){
108+
option[i].setAttribute("onclick", "optionSelected(this)");
109+
}
110+
}
111+
// creating the new div tags which for icons
112+
let tickIconTag = '<div class="icon tick"><i class="fas fa-check"></i></div>';
113+
let crossIconTag = '<div class="icon cross"><i class="fas fa-times"></i></div>';
114+
115+
//if user clicked on option
116+
function optionSelected(answer){
117+
clearInterval(counter); //clear counter
118+
clearInterval(counterLine); //clear counterLine
119+
let userAns = answer.textContent; //getting user selected option
120+
let correcAns = questions[que_count].answer; //getting correct answer from array
121+
const allOptions = option_list.children.length; //getting all option items
122+
123+
if(userAns == correcAns){ //if user selected option is equal to array's correct answer
124+
userScore += 1; //upgrading score value with 1
125+
answer.classList.add("correct"); //adding green color to correct selected option
126+
answer.insertAdjacentHTML("beforeend", tickIconTag); //adding tick icon to correct selected option
127+
console.log("Correct Answer");
128+
console.log("Your correct answers = " + userScore);
129+
}else{
130+
answer.classList.add("incorrect"); //adding red color to correct selected option
131+
answer.insertAdjacentHTML("beforeend", crossIconTag); //adding cross icon to correct selected option
132+
console.log("Wrong Answer");
133+
134+
for(i=0; i < allOptions; i++){
135+
if(option_list.children[i].textContent == correcAns){ //if there is an option which is matched to an array answer
136+
option_list.children[i].setAttribute("class", "option correct"); //adding green color to matched option
137+
option_list.children[i].insertAdjacentHTML("beforeend", tickIconTag); //adding tick icon to matched option
138+
console.log("Auto selected correct answer.");
139+
}
140+
}
141+
}
142+
for(i=0; i < allOptions; i++){
143+
option_list.children[i].classList.add("disabled"); //once user select an option then disabled all options
144+
}
145+
next_btn.classList.add("show"); //show the next button if user selected any option
146+
}
147+
148+
function showResult(){
149+
info_box.classList.remove("activeInfo"); //hide info box
150+
quiz_box.classList.remove("activeQuiz"); //hide quiz box
151+
result_box.classList.add("activeResult"); //show result box
152+
const scoreText = result_box.querySelector(".score_text");
153+
if (userScore > 3){ // if user scored more than 3
154+
//creating a new span tag and passing the user score number and total question number
155+
let scoreTag = '<span>and congrats! , You got <p>'+ userScore +'</p> out of <p>'+ questions.length +'</p></span>';
156+
scoreText.innerHTML = scoreTag; //adding new span tag inside score_Text
157+
}
158+
else if(userScore > 1){ // if user scored more than 1
159+
let scoreTag = '<span>and nice , You got <p>'+ userScore +'</p> out of <p>'+ questions.length +'</p></span>';
160+
scoreText.innerHTML = scoreTag;
161+
}
162+
else{ // if user scored less than 1
163+
let scoreTag = '<span>and sorry , You got only <p>'+ userScore +'</p> out of <p>'+ questions.length +'</p></span>';
164+
scoreText.innerHTML = scoreTag;
165+
}
166+
}
167+
168+
function startTimer(time){
169+
counter = setInterval(timer, 1000);
170+
function timer(){
171+
timeCount.textContent = time; //changing the value of timeCount with time value
172+
time--; //decrement the time value
173+
if(time < 9){ //if timer is less than 9
174+
let addZero = timeCount.textContent;
175+
timeCount.textContent = "0" + addZero; //add a 0 before time value
176+
}
177+
if(time < 0){ //if timer is less than 0
178+
clearInterval(counter); //clear counter
179+
timeText.textContent = "Time Off"; //change the time text to time off
180+
const allOptions = option_list.children.length; //getting all option items
181+
let correcAns = questions[que_count].answer; //getting correct answer from array
182+
for(i=0; i < allOptions; i++){
183+
if(option_list.children[i].textContent == correcAns){ //if there is an option which is matched to an array answer
184+
option_list.children[i].setAttribute("class", "option correct"); //adding green color to matched option
185+
option_list.children[i].insertAdjacentHTML("beforeend", tickIconTag); //adding tick icon to matched option
186+
console.log("Time Off: Auto selected correct answer.");
187+
}
188+
}
189+
for(i=0; i < allOptions; i++){
190+
option_list.children[i].classList.add("disabled"); //once user select an option then disabled all options
191+
}
192+
next_btn.classList.add("show"); //show the next button if user selected any option
193+
}
194+
}
195+
}
196+
197+
function startTimerLine(time){
198+
counterLine = setInterval(timer, 29);
199+
function timer(){
200+
time += 1; //upgrading time value with 1
201+
time_line.style.width = time + "px"; //increasing width of time_line with px by time value
202+
if(time > 549){ //if time value is greater than 549
203+
clearInterval(counterLine); //clear counterLine
204+
}
205+
}
206+
}
207+
208+
function queCounter(index){
209+
//creating a new span tag and passing the question number and total question
210+
let totalQueCounTag = '<span><p>'+ index +'</p> of <p>'+ questions.length +'</p> Questions</span>';
211+
bottom_ques_counter.innerHTML = totalQueCounTag; //adding new span tag inside bottom_ques_counter
212+
}
213+

0 commit comments

Comments
 (0)