How to add a high score to a game in WoofJS

2D Game Design with WoofJS

🕑 This lesson will take about 10 minutes

In this lesson, you will learn how to add a high score to a game in WoofJS, as shown in the example below. To add a high score, we will need to use the localStorage.getItem() and localStorage.setItem() functions to keep a record of the player’s high score in the browser’s local storage and then fetch this record when the player returns to the game. With Local Storage, you can store data locally within the user's browser. This data will be saved on the user’s device until they clear their browser cache.

Create a new project at woofjs.com and use the following code to implement this feature. Make sure you pay attention to the comments in the code that explain how it works.