I definitely ran into some frustrations with this assignment, but the payoff was worth it. My biggest speedbump was checking the accuracy of an answer in my checkGues function. I tested to see if the value returned by clicking A, B, C, or D matched the correct answer code within each question’s array, using something like this:
guessClick == (this["question" + packageCounter]);
For some reason though, I could never get this to work. I only started having luck when I assigned the correct answer code to a new variable within the init() function, like so:
answerStorage = this["question" + packageCounter];
Then, my checkGuess function worked flawlessly with “if (guessClick == answerStorage),” and this setup allowed me to easily add as many questions as I wanted. I stopped at 5, but I could have added as many as I wanted, without writing any extra code for each question.
My other big issue was getting the score counters to function. Originally I had a single-character textbox for the total correct, and another for the total wrong. Unfortunately, I had trouble properly casting the “correct” and “wrong” unsigned integers into strings, so they wouldn’t show up in my textbox. I ended up adding some words to the textboxes, and getting the number to show up like so:
correctScore.text = ("Correct: " + correct); wrongScore.text = ("Incorrect: " + wrong);
My last major hurdle was in figuring out why the aforementioned correct and incorrect scores were increasing by factors of two each time I hit the next button. For example, my “correct” score, assuming I answered everything correctly, went 1, 3, 7, 15, 31. I realized I needed to remove my event listeners before going back to init(), because otherwise it would be running every function twice…or something like that.
Overall, there were some frustrating moments, but it came together quickly because I coded it to move between questions seamlessly without any extra code.