-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.js
61 lines (50 loc) · 1.89 KB
/
quiz.js
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
// Web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyAbFistmgFQcIOojLVD7cgXmTE9mLvuqVc",
authDomain: "quizapp-74d37.firebaseapp.com",
databaseURL: "https://quizapp-74d37.firebaseio.com",
projectId: "quizapp-74d37",
storageBucket: "quizapp-74d37.appspot.com",
messagingSenderId: "10113678267",
appId: "1:10113678267:web:d2aa73777b379fb241629e",
measurementId: "G-PEKPZ347TY"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var database = firebase.database();
var getQuestion = document.getElementById("question");
var getAnswer1 = document.getElementById("answer1");
var getAnswer2 = document.getElementById("answer2");
var getAnswer3 = document.getElementById("answer3");
var getScore = document.getElementById("showScore");
var quizQuestions;
var questionId = 0;
var score = 1;
// getting quiz data from Firebase
database.ref('QuizData').on('value', function(questions){
quizQuestions = questions.val();
});
let getQuest = () => {
//for (question in quizQuestions) {
getQuestion.innerHTML = quizQuestions[questionId].question;
getAnswer1.innerText = quizQuestions[questionId].answer1;
getAnswer2.innerText = quizQuestions[questionId].answer2;
getAnswer3.innerText = quizQuestions[questionId].answer3;
getScore.innerText = score;
if(quizQuestions[questionId].correctAnswer)
{}
//}
}
setInterval(getQuest, 1000);
//quizQuestions[1].correctAnswer;
questionId = questionId + 1;
// showing quiz data
let nextQuestion = () => {
questionId = questionId + 1;
getQuestion.innerHTML = quizQuestions[questionId].question;
getAnswer1.innerText = quizQuestions[questionId].answer1;
getAnswer2.innerText = quizQuestions[questionId].answer2;
getAnswer3.innerText = quizQuestions[questionId].answer3;
console.log(quizQuestions[question].correctAnswer)
questionId = questionId;
}