Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

quiz javascript example with array

var questions = [
["What is the capital of England?", "LONDON", "You know, where the queen lives"],
["What is the capital of France?", "PARIS", "Remember the eiffel tower?"],
["What is the capital of Canada?", "OTTAWA", "Lot of mooses there"]
];

var correctAnswers = 0;

for (var i = 0; i < questions.length; i++) {
    var answer = prompt(questions[i][0]);
    if (answer.toUpperCase() == questions[i][1]) {
        alert("Correct! " + questions[i][2]);
        correctAnswers++;
    }
    else {
        alert("incorrect, the correct answer was " + questions[i][1]);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: New JSDOM and querySelector elems textContent 
Javascript :: jquey datatables 
Javascript :: postman environment variables 
Javascript :: json comment 
Javascript :: invariant failed: you should not use <link outside a <router 
Javascript :: add parameter at the end of url from jquery with refreshing 
Javascript :: How to end a session in ExpressJS 
Javascript :: javascript scroll 
Javascript :: js array .filter 
Javascript :: mysql json 
Javascript :: video conferencing app with html and js 
Javascript :: check if browser supports Local Storage 
Javascript :: jQuery - Add Elements 
Javascript :: add and remove class in jquery 
Javascript :: javascript add to home screen button 
Javascript :: settimeout with loop js 
Javascript :: setup react app from cpanel 
Javascript :: return inside for loop javascript 
Javascript :: fingerprint js 
Javascript :: copy object with new property in js 
Javascript :: upload file to database with axios and formData 
Javascript :: sort numbers in array in js 
Javascript :: database in javascript 
Javascript :: jquery get textarea value 
Javascript :: order by mongodb 
Javascript :: how to append response header in node 
Javascript :: create new component in angular 
Javascript :: search an array with regex javascript indexOf 
Javascript :: javascript check if length is greater than 0 
Javascript :: javascript less than but greater than 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =