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

JavaScript

Joseph Cho
Joseph Cho
5,544 Points

Keeping score on a web app

Hi, I'm part of a team trying to make a web app that basically presents the user with a bunch of different medical-based multiple choice questions. Each question is its own html file. We want to have another html page that displays the user's scores for each question depending on whether they got the question right in one try (1 point) or multiple tries (we take off points for incorrect tries).

How do we tally the overall score of the user? We know we're going to have to use variables in javascript but we don't know how to tally the score across all the different html pages.

We understand that it would be easy to just have all the questions in one html file, use one javascript file to keep track of the score and then notify the user at the end. We're wondering if it's possible for each question to be its own separate page and still keep track of the user's performance using one javascript file.

1 Answer

Hi Joseph,

Look into using HTML5's localStorage or sessionStorage capabilities. You can use these with all of the popular browsers including IE11 down to IE8, at least.

One article on HTML5 localStorage: http://diveintohtml5.info/storage.html

Another article that features both storage types: http://www.w3schools.com/html/html5_webstorage.asp