7 Replies Latest reply on Mar 14, 2014 8:27 PM by The shizzolator

    How do I get the sum of my variables and display the total?

    KreatorGuy

      I have written out a quiz and have each button setting a variable, example: http://www.kreativitydesigns.com/Clients/Globus/Monograms/MBA_Test/deliverables/MBA_Quiz.h tml?mode=preview

       

      However, when it hits the "Grade" frame to calculate and display the total, it is not displaying. 

      I do have the text box named "Grade" on stage and the variables have all been given a value before entering this frame

       

      Here is the code used to calcualte and output the result:

       

      //get the value of a variables and store them

      var FinalScoreHolder = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16 + q17 + q18 + q19 + q20 + q21 + q22 + q23 + q24 + q25 + q26 + q27 + q28 + q29 + q30 + q31 + q32 + q33 + q34 + q35 + q36 + q37 + q38 + q39 + q40;

       

      //Display the Grade

      sym.$("Grade").html("You scored "+FinalScoreHolder+"%");

       

       

      //Show Result Page

      if (FinalScoreHolder >= 89) {

       

      // play the timeline from the given position (ms or label)

      sym.play("pass");

       

      } else {

       

      // play the timeline from the given position (ms or label)

      sym.play("fail");

      }

       

      Any help would be greatly appreciated.

       

      Thanks!

        • 1. Re: How do I get the sum of my variables and display the total?
          resdesign Adobe Community Professional & MVP

          Your code is fine but it seems that it may not be getting the values of your questions because if you put the values as bellow I get the expected result.

           

          q1 = 20;

          q2 = 63;

          q3 = 12;

          //get the value of a variables and store them

          var FinalScoreHolder = q1 + q2 + q3;

           

           

          //Display the Grade

          sym.$("grade").html("You scored "+FinalScoreHolder+"%");

            

           

          //Show Result Page

          if (FinalScoreHolder >= 89) {

           

           

          // play the timeline from the given position (ms or label)

          sym.play("pass");

           

          } else {

           

          // play the timeline from the given position (ms or label)

          sym.play("fail");

          }

           

          11-12-2012 1-50-32 PM.png

          • 2. Re: How do I get the sum of my variables and display the total?
            KreatorGuy Level 1

            So, I am assigning the variables for q1, q2, q3, etc... on the click function, based on which answer they give, is there something I need to do to bring those values into the "Grade" frame, other than what I have done?

             

            I am declaring the variables like this:

             

            if they click "A" I run this:

             

            q2 = 0;
            sym.play("q2w");

             

             

             

             

             

            if they click "B" I run this:

             

            q2 = 2.5;
            sym.play("q3");

             

             

            Once they go through and answer everything, I need it to display the sum. Thanks again for taking the time to help. It means a great deal to me.

            • 3. Re: How do I get the sum of my variables and display the total?
              resdesign Adobe Community Professional & MVP

              with this code below, I get the result. So I am not sure why your animation does not read the variable values.

               

              i = 0;

              sym.$("btn").click(function(){

                        i++;

                        sym.play("s" + i);

                        if (i==1){

                                  q1 = 20;

                                

                        }

                        if (i==2){

                                  q2 = 10;

                                 

                        }

                        if (i==3){

                                  q3 = 10;

                                

                        }

                        var FinalScoreHolder = q1 + q2 + q3;

                        if (i=4){

                                  //var FinalScoreHolder = q1 + q2 + q3;

                                  sym.$("grade").html("You scored "+FinalScoreHolder+"%");

                                  if (FinalScoreHolder >= 89) {

               

               

                                  // play the timeline from the given position (ms or label)

                                  sym.play("pass");

               

               

                                  } else {

               

               

                                  // play the timeline from the given position (ms or label)

                                  sym.play("fail");

                                  }

                        }

              });

              1 person found this helpful
              • 5. Re: How do I get the sum of my variables and display the total?
                KreatorGuy Level 1

                I had quotes around the amount in the declaration.  Your code helped IMMENSLY, redesign. Thanks again!

                • 7. Re: How do I get the sum of my variables and display the total?
                  The shizzolator

                  Hi there

                   

                  Just wanted to express my thanks for this post and answer

                   

                  I just have two questions how do I set up a situation where the user has two possible answers, in the demo that you uploaded I can only see the open to answer correctly

                   

                  Plus is there anyway to setup and screen that lets the user fill in there email so the results can be emailed to them?

                   

                  Any help would be much appreciated

                   

                  George