Trying to create a flashcard app with cards made using user input and then saved into local storage so it can be accessed even after refreshing.
const newBtn = document.getElementById("newBtn")
function getWordList() {
return JSON.parse(localStorage.getItem("wordList") || "\[\]")
}
function saveWord(list) {
localStorage.setItem("wordList", JSON.stringify(list));
}
function addWord() {
let list = getWordList();
const newWord = {
id : document.getElementById("english").value,
english : document.getElementById("english").value,
japanese : document.getElementById("japanese").value
};
list.push(newWord);
saveWord(list);
}
document.addEventListener('DOMContentLoaded', ()=\>{
newBtn.addEventListener("click", addWord);
});
- User puts text in input field
- Submit Button is Pressed
- word list is accessed from local storage
- inputs are used to create a new object
- object is pushed into the word list
- word list is then saved with the new object added
I feel like all of the pieces are there but i'm assembling it incorrectly.