diff --git a/index.html b/index.html index 8046f00..10cc434 100644 --- a/index.html +++ b/index.html @@ -5,22 +5,32 @@ Note Taker App +

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 e69de29..080e63d 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,18 @@ +function getNoteId() { + let noteObject = getExistingNotes() + if (!noteObject) { + return 1 + } + const keysArray = Object.keys(noteObject) + const numberKeys = keysArray.map((key) => Number(key)) + console.log(numberKeys) + return Math.max(...numberKeys) + 1 +} + +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..a5b2215 100644 --- a/index2.html +++ b/index2.html @@ -11,10 +11,21 @@ -

Back

+ +

Back

+
\ No newline at end of file