4 Replies Latest reply on Dec 3, 2013 4:09 PM by cobbcobb2

    JS for randomizing tiered quiz questions?

    Kevin McMahon

      Alright noble edge users out there - I could really use your help:

       

      I am creating a quiz in edge with 10 levels - each level asks a question dealing with a particular topic for that level.  To make it more challenging/random, I want to allow each level's question to pull from a pool of 2-3 possible questions for that particular level (rather than one general pool for all 10 questions).

       

      I have created symbols out of each question - and played with a few randomizing options - but I am a tragically front-end designer

       

      Any help is greatly appreciate!

        • 1. Re: JS for randomizing tiered quiz questions?
          cobbcobb2

          A lot of that depends on how you've structured your game. Hopefully someone can add to this, but If you're wanting to stick mostly to coding from the timeline in edge animate, then you could do something like this:

           

          1) Insert a timeline label at the location of each question.

           

          2) Insert a timeline trigger at the beginning of your animation to create global array that contains the names of each timeline label for your questions. Something like this:

           

               window.possible_questions = ["Timeline Label 1","Timeline Label 1","Timeline Label 1","Timeline Label 1"];

           

           

           

           

          3) After you create the possibleQuestions array you can then send the user to the first random question by generating a random array index within the range of the remaining questions using something like this:

           

           

           

           

               //generate random index

               var random_index = Math.floor(Math.random() * possible_questions.length);

           

               //store the next question label

               var next_question = possible_questions[random_index];

           

               //remove the label from the array so we don't come back to it again

               possible_questions.splice(random_index, 1);

           

               //send the player to that label

               sym.stop(next_question);

           

           

          4) At each question, put something like this. If you want to detect the end of the game you can do that as well:

           

               if(possible_questions.length == 0){

           

           

                    //game is done

                    sym.stop("End of Game Timeline Label");

           

               }else{

           

                    //we have more questions to ask

           

                    //generate random index

                    var random_index = Math.floor(Math.random() * possible_questions.length);

           

                    //store the next question label

                    var next_question = possible_questions[random_index];

           

                    //remove the label from the array so we don't come back to it again

                    possible_questions.splice(random_index, 1);

           

                    //send the player to that label

                    sym.stop(next_question);

           

               }

          1 person found this helpful
          • 2. Re: JS for randomizing tiered quiz questions?
            Kevin McMahon Level 1

            CobbCobb2,

             

            Thanks so much for your thoughful and thorough response.  I will give it a go.  In the meantime, I had devised a rather hokey, non-coder solution.  It might be good for a laugh:

             

            I have:

             

            1) Copied the button that triggers the questions x 3.

            2) Made each copied button display on and off in a looping sequence in the same location (so it appears to be the same button.)

            3) Associated each of the 3 buttons with 3 different possible questions.

             

            So essentially, its not random - but depends on when the user clicks during the button cycle. At least it will add some level of variation and surprise.

             

            Not graceful, but it works .

            • 3. Re: JS for randomizing tiered quiz questions?
              elainecc Adobe Employee

              Hi, Kevin-

               

              I wrote a blog post a couple of months ago that might help you learn more about randomization:

               

              http://blogs.adobe.com/edge/2013/09/19/floral-matchmaker-tutorial-4-randomizing-the-game-b oard/

               

              Hope this helps,

               

              -Elaine

              • 4. Re: JS for randomizing tiered quiz questions?
                cobbcobb2 Level 1

                Don't be ashamed of hokey solutions...believe me...the path to graceful solutions is paved with hokey, pain-in-the-butt, this-will-come-back-to-haunt-you solutions! Keep improving your understanding and look at how other people solve similar problems. The beauty of well formatted code and good logic is for your sake when you come back to the code later on or if you want to expand the code to cover more questions or topics in the future.

                 

                The solution I gave you would randomize the levels in your case. If you wanted to randomize a question at a particular level you could in theory create an array for each question, randomize the index, and then populate the question and answer texts before showing them to the user. Much of the same logic is at play, it's just a matter of hiding the information from the user until you're ready to show it to them.

                 

                You can use a call like this to update the html inside of a text box:

                sym.$("question_text_holder").html("Question text");

                 

                As always...there's more than one way to do it.