Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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