From 3d12cc0142ff5ac4bf14da54f5a452a7f0836fe2 Mon Sep 17 00:00:00 2001 From: mrsturner Date: Fri, 9 Apr 2021 10:44:54 -0500 Subject: [PATCH 1/4] Copied the coded from the youtube. I did not understand how local storage was working. --- index.html | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 8046f00..d4bdea0 100644 --- a/index.html +++ b/index.html @@ -5,22 +5,21 @@ Note Taker App +

Note Taker App

- -
- + +
+ + View Notes +
- - - + + + + \ No newline at end of file From 9e5599bac7057c48d82864316f15b5958e2200fb Mon Sep 17 00:00:00 2001 From: mrsturner Date: Fri, 9 Apr 2021 10:45:50 -0500 Subject: [PATCH 2/4] staging all changes --- index.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/index.js b/index.js index e69de29..0771821 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,26 @@ +var textElement = document.getElementById("note") + +function saveNote() { + if (textElement.value = "") { + return alert('text is empty!') + } + const id = getNoteId() + let noteObject = gtExistingNOtes() + if (!noteObject) { + noteObject = {} + } + noteObject[id] = textElement.value + localStorage.setItem('notes', JSON.stringify(noteObject)) + alert('Note Saved!') +} + +function getNotes() { + let notes = getExistingNotes() + let notesArray = Object.values(notes) + let orderedList = document.getElementById('notes-list') + notesArray.forEach(note => { + let listItem = document.createElement('li') + listItem.innerHTML = note + orderedList.appendChild(listItm) + }) +} \ No newline at end of file From 200c53906e0d807daa78f999a0f8c9196785c9ae Mon Sep 17 00:00:00 2001 From: mrsturner Date: Sun, 11 Apr 2021 13:56:10 -0500 Subject: [PATCH 3/4] Changed to match video --- index.html | 21 ++++++++++++++++----- index.js | 34 +++++++++++++--------------------- index2.html | 16 +++++++++++++--- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index d4bdea0..73d3352 100644 --- a/index.html +++ b/index.html @@ -16,10 +16,21 @@

Note Taker App

View Notes -
-
    + + function saveNote() { + if (textElement.value == "") { + return alert('text is empty!') + } + const id = getNoteId() + let noteObject = getExistingNotes() + if (!noteObject) { + noteObject = {} + } + noteObject[id] = textElement.value + localStorage.setItem('notes', JSON.stringify(noteObject)) + alert('Note Saved!') + } + \ No newline at end of file diff --git a/index.js b/index.js index 0771821..080e63d 100644 --- a/index.js +++ b/index.js @@ -1,26 +1,18 @@ -var textElement = document.getElementById("note") - -function saveNote() { - if (textElement.value = "") { - return alert('text is empty!') - } - const id = getNoteId() - let noteObject = gtExistingNOtes() +function getNoteId() { + let noteObject = getExistingNotes() if (!noteObject) { - noteObject = {} + return 1 } - noteObject[id] = textElement.value - localStorage.setItem('notes', JSON.stringify(noteObject)) - alert('Note Saved!') + const keysArray = Object.keys(noteObject) + const numberKeys = keysArray.map((key) => Number(key)) + console.log(numberKeys) + return Math.max(...numberKeys) + 1 } -function getNotes() { - let notes = getExistingNotes() - let notesArray = Object.values(notes) - let orderedList = document.getElementById('notes-list') - notesArray.forEach(note => { - let listItem = document.createElement('li') - listItem.innerHTML = note - orderedList.appendChild(listItm) - }) +function getExistingNotes() { + let notes = localStorage.getItem('notes') + if (!notes) { + return null + } + return JSON.parse(notes) } \ No newline at end of file diff --git a/index2.html b/index2.html index b4394a5..358800e 100644 --- a/index2.html +++ b/index2.html @@ -11,10 +11,20 @@
-

Back

+ +

Back

+
\ No newline at end of file From 7f06031e9254f6b82084b18e6a321194a4fca7dc Mon Sep 17 00:00:00 2001 From: mrsturner Date: Mon, 12 Apr 2021 04:46:20 -0500 Subject: [PATCH 4/4] Added parenthesis in index.html2 --- index.html | 2 +- index2.html | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 73d3352..10cc434 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@

Note Taker App

var textElement = document.getElementById("note") function saveNote() { - if (textElement.value == "") { + if (textElement.value === "") { return alert('text is empty!') } const id = getNoteId() diff --git a/index2.html b/index2.html index 358800e..a5b2215 100644 --- a/index2.html +++ b/index2.html @@ -17,14 +17,15 @@

Back

\ No newline at end of file