Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Leigh Maher
21,830 PointsJavascript Quiz Problems with Adding Previous Question Button
I've created a quiz in Javascript. It worked fine before I tried to add a previous question button. I've had to break out the code into a number different functions in order to get it working, but I've run into 2 problems:
- When I click on previous question, I want the option that the user previously selected for that question to be selected. The problem I'm having is that it pre-selects the next question with the same option number. I can understand why this isn't working as it should, but I don't know where to move the code for this part to make it behave properly.
Here's the bit of code from the quiz function:
if (i == userAnswer) {
optionButton.checked = true;
}
Here's the full quiz on jsfiddle: https://jsfiddle.net/leighm/gofxaujb/10/
- When the user clicks on next question without choosing an option, they get an alert telling them they need to select an option. However, when the user clicks ok on the alert, the programme continues to the next question, anyway. I need it to remain on the same question until the user selects an option.
Here's the full quiz on jsfiddle: https://jsfiddle.net/leighm/gofxaujb/10/
Thanks.