localStorage

Local storage saves information in the browser of the user. It can be used to save preferences, previous scores in a game, etc.

Important Functions to Know

  • storeItem() stores a value in local storage under the key name

  • getItem() returns the value of an item that was stored in local storage using storeItem()

  • removeItem() removes an item that was stored with storeItem()

  • clearStorage() clears all local storage items set with storeItem() for the current domain

Bouncing Ball Demo

Use localStorage to keep track of the number of times the ball has bounced off the side of the screen. Show the current record as well as the current number of bounces. Reset the bounces to be 0 when the user presses ‘r’.

Next Section - p5.sound Library