Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //array quiz program
- //should keep track of number of correct answers
- //should display number of correct asnwers
- //display the correct and false questions seperately
- //use two dimensional array for qeustions and asnwers
- var quiz=[
- ['how old is Messi?',30],
- ['how old is Iniesta?',32],
- ['how old is neymar?',25]
- ];
- function print(message) {
- document.write(message);
- }
- var correct=0;
- var correctquestion=[];
- var falsequestion=[];
- var question1=prompt(quiz[0][0]);
- if(parseInt(question1)===quiz[0][1]){
- correct +=1;
- }
- if(parseInt(question1)===quiz[0][1]){
- correctquestion.unshift(quiz[0][0]);
- }else{
- falsequestion.unshift(quiz[0][0]);
- }
- //-----------------------------
- var question2=prompt(quiz[1][0]);
- if(parseInt(question2)===quiz[1][1]){
- correct +=1;
- }
- if(parseInt(question2)===quiz[1][1]){
- correctquestion.unshift(quiz[1][0]);
- }else{
- falsequestion.unshift(quiz[1][0]);
- }
- //--------------------------------------
- var question3=prompt(quiz[2][0]);
- if(parseInt(question3)===quiz[2][1]){
- correct +=1;
- }
- if(parseInt(question3)===quiz[2][1]){
- correctquestion.unshift(quiz[2][0]);
- }else{
- falsequestion.unshift(quiz[2][0]);
- }
- //-------------------------------
- print("the number of correct answers is " + correct +"</br>");
- for (i=0; i<correctquestion.length; i++){
- print("Correct questions are </br>" +correctquestion[i]+ "</br>");}
- for (i=0; i<falsequestion.length; i++){
- print("False questions are </br>" +falsequestion[i] + "</br>");}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement