I'm working on the JS game. How do you keep the record?
-
I'm a newcomer, as you understand. I'm working on a course-work game. I'm doing it on a clean JavaScript. The game is complete, except for the preservation of statistics. The game is very simple - the game of bone. There's a point in the course requirements that sounds like, "Let's keep the players' results. " The question is, how do you do it better? We need to take into account the fact that the game now exists in the form of a file folder and starts at the browser by opening the HTML file. Consider keeping statistics in a local file or keeping it in Cookie. Until such time as he was aware of these ways, and in order not to waste time, he decided to ask this question and to learn from the more experienced people how to organize statistics. There are two variables, one with a player's name, one with a number of points. I need the statistics to be recorded when the button is pressed (the button is already ready, only to write the code in) and then I can paint the table of players and their results (preferably with the possibility of sorting the number of points).
-
Better learn SQL. If you want, you'll learn in two days. The simplest way to store in localStorage. But there's probably some kind of bullshit coming out. The following example illustrated how to set localStorage values and how to get them. Default default, set two early names and zero points. And every push on the button, make a new setItem, for rewriting. We'll write questions together. Considering that you don't have more than two names on the leadership board, you need a database, preferably on SQL.
localStorage.setItem('user1', JSON.stringify([name1, point1]));
localStorage.setItem('user2', JSON.stringify([name2, point2]));
const user1 = localStorage.getItem('user1');
const user2 = localStorage.getItem('user2');