forked from adaapp/di-workshop-quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.js
41 lines (35 loc) · 1.48 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
var score = 0;
var username;
var QuestionOne = "Berlin is the capital of which country? a)Germany, b)Belgium c) Netherlands"
var AnswerOne = "a"
var userAnswerOne;
var questions = ["Berlin is the capital of which country? a)Germany, b)Belgium c) Netherlands", "Does the moon have gravity? a)Yes its 1.622 m/s b)No there is no gravity where you float", "You want to make green paint. Which colours do you miss together? a) red and yellow b) orange and purple c) blue and yellow"]
var answers = ["a", "a", "b"]
function startGame() {
// get the user's name
username = prompt("Welcome to the General quiz, What is your name?")
// AskQuestion(questions[0], answers[0])
// AskQuestion(questions[1], answers[1])
// AskQuestion(questions[2], answers[2])
for(var i = 0; i < questions.length; i++) {
AskQuestion(questions[i], answers[i])
}
alert( username + " ,your score is " +score);
// alert(username)
// userAnswerOne = prompt("Welcome, " +username+". Your first question is:" + QuestionOne);
// if (userAnswerOne == AnswerOne ){
// score++
// } else{
// alert("The answer was " +AnswerOne)
// }
// console.log (userAnswerOne, AnswerOne)
}
function AskQuestion(question, correctAnswer) {
var userAnswer = prompt(question);
if(userAnswer.toLowerCase() == correctAnswer.toLowerCase()) {
score++
} else {
alert("The answer was " +AnswerOne)
}
} // this is the end of the AskQuestion function
console.log(score)