How to keep a scoring history?
I have written a small app using jQuery Mobile and Phonegap in which the user is given some text to correct and when he is finished he clicks on a "Get Score" button and is shown in an alert how many answers were correct and how many were incorrect.
I would like to improve this so that after being shown the latest results the user is shown his score for today and for previous days.
I started by adding a page with a text box and then comparing today's date with the last date used which lis stored via localStorage. I then compare the two date strings and if today is a new day load the old results from
localStorage and write them to a text box. I would then like to append the new results to this list and if the user has another try on the same day replace the appended score with the latest score for today. When the user leaves the entire list is saved to
localStorage ready for the next time he uses the app.
I'm afraid I have got myself tied up in a knot with what surely is a simple task. Here is the relevant part of my script as it stands, some lines are commented out from my attempts to find out what I'm doing wrong.
Any advice would be welcome, even if it is scrap the lot and do it this way.
- storedDate = localStorage.getItem("storeDate");
- if(storedDate === todaysDate){
- // $('#totalText').last().remove();
- totalPlus = totalPlus + plusPoints;
- totalMinus = totalMinus + minusPoints;
- result = todaysDate + " correct " + totalPlus + " incorrect " + totalMinus + "<br>";
- $('#totalText').append(result);
- // $('#totalText').append('<div class="added"></div>');
- // $('.added').html(result);
- }
- else {
- var resultHistory = localStorage.getItem("resHistory");
- $('#totalText').append(resultHistory);
- // $('#totalText').append('<div class="history"></div>');
- // $('.history').html(resultHistory);
- localStorage.setItem("storeDate", todaysDate);
- totalPlus = plusPoints;
- totalMinus = minusPoints;
- result = todaysDate + " correct " + totalPlus + " incorrect " + totalMinus;
- // $('#totalText').append('<div class="added"></div>');
- // $('.added').html(result);
- }
- localStorage.setItem("resHistory", $('#totalText').html());