Skip to main content
Participant
May 8, 2013
Question

as3 quiz multiple take

  • May 8, 2013
  • 1 reply
  • 737 views

Good afternoon,

I am trying to make a quiz that will alow you to take it 3 times before the correct answer is shown.  I have the code working for just one take and then and instant answer, but I really need it to be 3 takes.  number ++; will let you take it three times but with no feedback or right answer when you hit it. Any help?

code_snippets

ans1.label = "";

ans2.label = "";

ans3.label = "";

ans4.label = "";

correct.visible = false;

incorrect.visible = false;

feedback.visible = false;

feedback_2.visible = false;

   

submitBtn.addEventListener(MouseEvent.CLICK, submitClick);

var number:int = 0;

function submitClick(e:MouseEvent):void

{

 

          number ++;

          if (number == 3){

                    answerCheck();

          }

 

}

function answerCheck(){

 

          if(ans1.selected == false && ans2.selected == false && ans3.selected == false && ans4.selected == true){

                    correct.visible = true;

          }

          else{

                    incorrect.visible = true;

          }

 

          //Disabled all buttons

          submitBtn.enabled = false;

          ans1.enabled = false;

          ans2.enabled = false;

          ans3.enabled = false;

          ans4.enabled = false;

 

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 9, 2013

First, it appears you do not want to be only running the answer check function when number == 3... I think you want to run it every try.

Secondly, you do not want to be disabling the things that you do in the answerCheck function until after the answers have been given.

Participant
May 9, 2013

Yes, your right I would like the check function to see ans1=1 ans2=1 ans3=1 ans4 =3.  I am just having a hard time wrapping my head around what the code should look like.  Do I just change the If, Else statement to have this or do I make a new If, Else to have the true false and one for the number ++.

Ned Murphy
Legend
May 10, 2013

If you want to check every try, but only allow three tries at most, then adjust your logic...

function submitClick(e:MouseEvent):void

{

          number ++;

          if (number < 3){

                    answerCheck();

          }

}

As far as wrapping your head around coding, don't let the code tell you what to do... it can't.  Just think thru what logic you would apply if you were the one controlling the action, and then gradually write the code to do it in logical steps... you do not have to solve the whole design in one try.