-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
25 lines (22 loc) · 852 Bytes
/
Copy pathmain.js
File metadata and controls
25 lines (22 loc) · 852 Bytes
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
// const myImage = document.querySelector('img');
// myImage.onclick = () => {
// const mySrc = myImage.getAttribute("src");
// if (mySrc === "images/firefox2.png")
// myImage.setAttribute("src", "images/firefox-icon.png");
// else if(mySrc === "images/firefox-icon.png")
// myImage.setAttribute("src", "images/firefox2.png");
// };
let myButton = document.querySelector('button');
let myHeading = document.querySelector('h1');
function setUserName() {
const myName = prompt("Enter your name...");
localStorage.setItem("name", myName);
myHeading.textContent = `Welcome, ${myName}`;
}
if (!localStorage.getItem("name"))
setUserName();
else {
const myName = localStorage.getItem("name");
myHeading.textContent = `Welcome, ${myName}`;
}
myButton.onclick = () => setUserName();