Skip to main content
bumbies
Known Participant
December 1, 2021
Question

Quiz with multiple button selections and retry button

  • December 1, 2021
  • 1 reply
  • 878 views

Been at this for a while but having trouble achieving what I need.
All & any help would be wonderful!

Here's the scenario & what I would like to achieve:

On a frame named QUIZ, users need to select the 3 correct buttons out of 5 options, to move on to the next frame.

1. If any option buttons are selected, the selected buttons remain on a down state.
2. If SUBMIT button is selected, and buttons selected are wrong, go to frame named WRONG
3. If SUBMIT button is selected, and buttons selected are correct, go to frame named CORRECT
4. If RETRY button is selected, go to frame named QUIZ, all buttons that were selected should be cleared and user can redo the quiz

From this link I can managed to do item 1.
https://community.adobe.com/t5/animate-discussions/keep-button-state/m-p/10120114

Any guidance on how to achieve items 2-4 will be very much appreciated! Thank you in advance!

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    December 1, 2021

    how many different questions are there?

     

    if there's more than one, are they all presented on the same quiz frame or do you have different quiz frames?

    bumbies
    bumbiesAuthor
    Known Participant
    December 1, 2021

    Hi kglad! Thank you for your reply.

    I would like have 3 questions in 1 frame like this:

    Question 1: Choose 3 correct out of the 5 options below.
    Answer1, Answer2, Answer3, Answer4, Answer5

    Question 2: Choose 3 correct out of the 5 options below.
    Answer1, Answer2, Answer3, Answer4, Answer5

    Question 3: Choose 3 correct out of the 5 options below.
    Answer1, Answer2, Answer3, Answer4, Answer5

    SUBMIT RETRY

    However if it is too complicated, I can also have 1 question per frame.

    Eagerly awaiting your reply. Thank you!

    kglad
    Community Expert
    Community Expert
    December 4, 2021

    if(!this.alreadyExecuted){

    this.questionA=['question1', 'question2',question3'];

    this.answerOptionsA=[['answer1 to q1','answer2 to q1',..,'answer5 to q1'],['answer1 to q2','answer2 to q2',etc],['answer1 to q3', etc]];

    this.correctAnswerA=[[0,2,3],[1,3,4],[2,3,4]];  // the indices of the correct answers from this.answerOptionsA

    this.questionNum=0;

    this.alreadyExecuted=true;

    }

     

    // display question = this.questionA[this.questionNum)

    // display answer1 = this.answerOptionsA[this.questionNum,0];

    // display answer2 = this.answerOptionsA[this.questionNum,1];

    // etc

     

    this.submit.addEventListener("click",submitF.bind(this));

     

    function submitF(){

    var correctResponse = true;

    for(var i=0;i<5;i++){

    if(this.answerButton[i].currentLabel=='down'){  // name your answer buttons, answerButton0, answerButton1, etc and label your down frame, 'down'.

    if(this.correctAnswerA[this.questionNum].indexOf(i)>-1){

    // correct

    } else {

    // incorrect

    correctResponse = false;

    break;

    }

    } else {

    // button up

    if(this.correctAnswerA[this.questionNum].indexOf(i)>-1){

    // incorrect

    correctResponse = false;

    break;

    } else {

    correct

    }

    }

    }

    if(correctResponse){

    this.questionNum++;

    if(this.questionNum==3){

    // goto correct answer frame, but don't return here.  quiz is over

    } else {

    goto correct answer frame

    }

    // go to incorrect answer frame.  increment this.questionNum if they'll be presented with the next question, or do not if they have to retry getting this question answered correctly.

    }

    }

     

     

    p.s. i didn't realize this was going to be so long when i started answering, so there's probably mismatched brackets in, at least, one location.