-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (33 loc) · 1.32 KB
/
script.js
File metadata and controls
41 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const rememberDiv = document.querySelector(".remember");
const forgetDiv = document.querySelector(".forget");
const form = document.querySelector("form");
const nameInput = document.querySelector("#entername");
const submitBtn = document.querySelector("#submitname");
const forgetBtn = document.querySelector("#forgetname");
const h1 = document.querySelector("h1");
const personalGreeting = document.querySelector(".personal-greeting");
form.addEventListener("submit", (e) => e.preventDefault());
submitBtn.addEventListener("click", () => {
localStorage.setItem("name", nameInput.value);
nameDisplayCheck();
});
forgetBtn.addEventListener("click", () => {
localStorage.removeItem("name");
nameDisplayCheck();
});
function nameDisplayCheck() {
if (localStorage.getItem("name")) {
const name = localStorage.getItem("name");
h1.textContent = `Welcome, ${name}`;
personalGreeting.textContent = `Welcome to our website, ${name}! We hope you have fun while you are here.`;
forgetDiv.style.display = "block";
rememberDiv.style.display = "none";
} else {
h1.textContent = "Welcome to our website ";
personalGreeting.textContent =
"Welcome to our website. We hope you have fun while you are here.";
forgetDiv.style.display = "none";
rememberDiv.style.display = "block";
}
}
nameDisplayCheck();