Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // Questions and Answers
  2. var quizQuestions = [
  3. ['What is the capitol of the Kingdom of Thailand?','Bangkok'],
  4. ['How high is the Eifeltower? \(Answer only in Numbers\)','125'],
  5. ['What is Darth Vader\s real name?','Anakin Skywalker'],
  6. ];
  7.  
  8. // HTML output message
  9. function print(message) {
  10. document.write(message);
  11. }
  12.  
  13. // Quiz Game
  14. function game(array) {
  15. for ( i = 0; i < 3; i += 1) {
  16. var correctAnswers = '0';
  17. var userAnswer = prompt(array[i][0]).toLowerCase();
  18. if (userAnswer === array[i][1].toLowerCase() ){
  19. correctAnswers += 1;
  20. array[i].push(true);
  21. } else if (userAnswer !== array[i][1].toLowerCase()){
  22. array[i].push(false);
  23. }
  24. console.log('Correct answers count: ' + correctAnswers);
  25. }
  26. document.write('<p>You correctly answered <strong>' + correctAnswers + '</strong> questions.</p>');
  27. document.write('<p><strong>You answered the following questions correct:</strong></p>');
  28. document.write('<ol>');
  29. for ( i = 0; i < 3; i += 1) {
  30. if ( array[i][2] ) {
  31. document.write('<li>' + array[i][0] + '</li>');
  32. }
  33. }
  34. document.write('</ol>');
  35. document.write('<p><strong>You ansered the following questions wrong:</strong></p>');
  36. document.write('<ol>');
  37. for ( i = 0; i < 3; i += 1) {
  38. if ( ! array[i][2] ) {
  39. document.write('<li>' + array[i][0] + '</li>');
  40. }
  41. }
  42. document.write('</ol>');
  43. }
  44.  
  45. // run Quiz Game with "quizQuestions" array
  46. game( quizQuestions );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement