Prep 8: 10.1, 10.4.1, and localStorage
Read 10.1, 10.4.1, and localStorage, and complete the activity.
Categories:
2 minute read
Read
- FunWebDev Chapter 10.1 (Array Functions)
- Yes, you’ve seen these before! Now’s a great time to review 😉
- FunWebDev Chapter 10.4.1 (brief overview)
- The Modern JavaScript Tutorial - localStorage
Activity
For this activity, you will be trying out localStorage
for yourself! Create two html files called save.html
and load.html
.
You may download this template file to help you get started.
save.html
- In a script element, write code to:
- Save your full name to a localStorage entry with the key
fullname
- Save your favorite number to an entry with the key
favnumber
- Save an array of at least three quotes to an entry with the key
quotes
- Hint: you will need to “stringify” the object
- Save your full name to a localStorage entry with the key
- In a script element, write code to:
load.html
- First, add three elements to display the saved data:
- A
div
with the idname-display
- A
div
with the idfavorite-display
- A
ul
with the idquotes-display
- A
- Then, in a script element (at the bottom of the
body
), write code to:- Load the value with the
fullname
key from localStorage and set the firstdiv
’stextContent
to that value - Load the value with the
favnumber
key, add 5 to it, and then set it to the seconddiv
- The value will be loaded as a string. You will need to convert it back to an int.
- Load the value with the
quotes
key and make a new list entry for each quote- Hint: you will need to “parse” the string and convert it back to an object
- Load the value with the
- First, add three elements to display the saved data:
Last modified August 11, 2024: moved a bunch of things for archival purposes (6652bbe)