seinfeld quiz game question array

Seinfeld Personality Type Quiz Part 2

This is an update from my previous post. I believe last time I was able to just acquire any input value from the radio fields the user selects. Now I made things a little more complex by including a shuffle function. This will randomize the questions and finding the answer with the highest value.

shuffle function to randomize the quiz questions
Shuffle function

The quiz questions are contained in an array of objects with the initial question and the available choices.

seinfeld quiz game question array

The question and choice values are kept pretty simple for test purposes so there is no right/wrong answer. Once the question array is set it’s passed through the shuffle function to randomize the placement of the questions. This way the game will randomize the question order on every play.

seinfeld quiz game question array shuffled

I needed to focus on some way to collect the score. Since this is a personality type quiz, there is no real wrong answer. Each answer is tied to a specific personality trait that starts at 0 (see image above). Depending on the answer the user gives, a +1 value will be given to the trait the choice is tied to via a switch statement. This is called by an event handler which also generates the next question.

seinfeld quiz game switch statement

The game adds the traits object and saves it to local storage. Once the next question is generated the script will parse it from local storage so the data can be manipulated again. When the game is over, the function findHighest will take that object to find which property has the highest value and alert it to the browser.

seinfeld quiz alerted answer

So far this seems to work. I’d like to work through is what if 2 or more properties have the same value. The current remedy I have for this is to prioritize via the switch statement in the findHighest function.