showing results for - "quiz javascript example with array"
Alessio
02 May 2017
1var questions = [
2["What is the capital of England?", "LONDON", "You know, where the queen lives"],
3["What is the capital of France?", "PARIS", "Remember the eiffel tower?"],
4["What is the capital of Canada?", "OTTAWA", "Lot of mooses there"]
5];
6
7var correctAnswers = 0;
8
9for (var i = 0; i < questions.length; i++) {
10    var answer = prompt(questions[i][0]);
11    if (answer.toUpperCase() == questions[i][1]) {
12        alert("Correct! " + questions[i][2]);
13        correctAnswers++;
14    }
15    else {
16        alert("incorrect, the correct answer was " + questions[i][1]);
17    }
18}
19