From 7d17082c384dc4c77a49c3d5d3d3e09c3ca1c690 Mon Sep 17 00:00:00 2001 From: Jaydeep Yadav <64890504+Jaydeep-Yadav@users.noreply.github.com> Date: Sat, 9 Oct 2021 15:22:46 +0530 Subject: [PATCH] Create app.js --- Note Taking Web App/js/app.js | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Note Taking Web App/js/app.js diff --git a/Note Taking Web App/js/app.js b/Note Taking Web App/js/app.js new file mode 100644 index 00000000..bc9bf598 --- /dev/null +++ b/Note Taking Web App/js/app.js @@ -0,0 +1,74 @@ +showNotes(); +let addBtn = document.getElementById("addBtn"); + +addBtn.addEventListener("click", function (e) { + let addTxt = document.getElementById("addTxt"); + let notes = localStorage.getItem("notes"); + if (notes == null) { + notesObj = []; + } else { + notesObj = JSON.parse(notes); + } + + notesObj.push(addTxt.value); + localStorage.setItem("notes", JSON.stringify(notesObj)); + addTxt.value = ""; + showNotes(); +}); + +function showNotes() { + let notes = localStorage.getItem("notes"); + if (notes == null) { + notesObj = []; + } else { + notesObj = JSON.parse(notes); + } + + let html = ""; + notesObj.forEach(function (element, index) { + html += ` +
${element}
+ +