Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Questions and Answers
- var quizQuestions = [
- ['What is the capitol of the Kingdom of Thailand?','Bangkok'],
- ['How high is the Eifeltower? \(Answer only in Numbers\)','125'],
- ['What is Darth Vader\s real name?','Anakin Skywalker'],
- ];
- // HTML output message
- function print(message) {
- document.write(message);
- }
- // Quiz Game
- function game(array) {
- for ( i = 0; i < 3; i += 1) {
- var correctAnswers = '0';
- var userAnswer = prompt(array[i][0]).toLowerCase();
- if (userAnswer === array[i][1].toLowerCase() ){
- correctAnswers += 1;
- array[i].push(true);
- } else if (userAnswer !== array[i][1].toLowerCase()){
- array[i].push(false);
- }
- console.log('Correct answers count: ' + correctAnswers);
- }
- document.write('<p>You correctly answered <strong>' + correctAnswers + '</strong> questions.</p>');
- document.write('<p><strong>You answered the following questions correct:</strong></p>');
- document.write('<ol>');
- for ( i = 0; i < 3; i += 1) {
- if ( array[i][2] ) {
- document.write('<li>' + array[i][0] + '</li>');
- }
- }
- document.write('</ol>');
- document.write('<p><strong>You ansered the following questions wrong:</strong></p>');
- document.write('<ol>');
- for ( i = 0; i < 3; i += 1) {
- if ( ! array[i][2] ) {
- document.write('<li>' + array[i][0] + '</li>');
- }
- }
- document.write('</ol>');
- }
- // run Quiz Game with "quizQuestions" array
- game( quizQuestions );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement