Skip to content

Commit

Permalink
add saving characters by localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Katarni committed Aug 2, 2024
1 parent e9cc096 commit 4614a55
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
if (localStorage.getItem("counting") === null) {
localStorage.setItem("counting", "0");
}

for (var i = 0; i < parseInt(localStorage.getItem("counting")); ++i) {
const character = document.createElement('div');
character.classList.add("charapter-box");
document.querySelector("main").appendChild(character);
}

function addCharacter() {
const character = document.createElement('div');
character.classList.add("charapter-box");
document.querySelector("main").appendChild(character);

localStorage.setItem("counting", (parseInt(localStorage.getItem("counting")) + 1).toString());
}

document.querySelector(".add-char-btn").addEventListener("click", () =>
addCharacter()
);
);

0 comments on commit 4614a55

Please sign in to comment.