Lab 10 - Card Creator
Categories:
3 minute read
Greeting Cards
In this (two-part) lab, you will write a tiny app to create greeting cards that you can send to your friends, family, and more! You will need the knowledge you’ve built in the past two preps (forms and localStorage).
For this lab, you will submit the assignment individually (but feel free to collaborate with others) via GitHub Classroom.
Getting Started
- Accept the assignment in GitHub Classroom using your instructor-provided link (in Canvas)
- Clone the newly-created repository on your computer
- Open the repository folder in VS Code
- Look over the provided code to get a feel for what it does and where you need to add your own
Creating the Form
We’ve provided the code and styles for the “preview” area of the page, but you’ll need to create a form and provide the functionality for a user to specify what their card’s title, message, to, from, etc. should be. Follow the image and the instructions below:
In card-creator.html
:
- Create an HTML
form
inside theform-area
- Give the form the class
card-form
- Give the form the class
- You will need four text
input
s and atextarea
, each with its ownlabel
- Put each group of
label
plusinput
in its owndiv
- Give this
div
a class ofform-group
- Give this
- Make sure to include
placeholder
text - You’ll want to make sure each element has a
name
andid
- Put each group of
- Add
button
s at the end of theform
- Put them inside a
div
with the classform-buttons
- The preview button should have
type="button"
- The save button should have
type="submit"
- Make sure they have
id
s, so you can access them easier in a script
- Put them inside a
Adding the Functionality
In the script.js
file, write some JavaScript to do the following:
- When the “preview” button is clicked, you should set the text in all the appropriate
span
s to the value of the corresponding control in the form. - When the “save” button is clicked, you should add the card to an array and save the array of cards to
localStorage
:-
You should start by loading the existing array from
localStorage
with the keycards
- If there doesn’t exist an entry with the key, create a new array and assign it to a variable
- If there does exist an entry with the key, you should parse it and assign it to a variable
-
Create a new JavaScript object (aka map/dictionary) to represent the current card
- It should have five properties:
to
,from
,title
,subtitle
, andmessage
- The properties should be set to the corresponding value from the form
- It should have five properties:
-
Add the new object to the end of the array
-
Store the array in
localStorage
to the entry with the keycards
, overwriting any existing entry- Don’t forget:
localStorage
only lets you store strings, so you’ll need to “stringify” the array!
- Don’t forget:
-
Saving multiple cards should result in an array containing all the cards. You can use the developer console in Chrome/Edge and Firefox to check if you’re doing this correctly:
-
Submission
Commit and push your code to GitHub.