Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ <h2 class="header">Note Taker App</h2>
var textElement = document.getElementById("note")

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!")
}
</script>
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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);
}
17 changes: 14 additions & 3 deletions index2.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@


<script>


</script>
(
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(listItem)

})
})()

</script>