Skip to content
Snippets Groups Projects
Commit 60f90ea2 authored by juchang Lee's avatar juchang Lee
Browse files

folder updated

parent 68c21566
Branches
No related tags found
No related merge requests found
No preview for this file type
File moved
......@@ -7,7 +7,7 @@
<title>Momentum App</title>
</head>
<body>
<form id="login-form>
<form class="hidden" id="login-form">
<input
required
maxlength="15"
......@@ -17,7 +17,6 @@
<input type="submit" value="Log In" />
</form>
<h1 id="greeting" class="hidden"></h1>
<a href="https://nomadcoders.co">Go to courses</a>
<script src="app.js"></script>
</body>
</html>
\ No newline at end of file
const loginForm = document.querySelector("#login-form");
const loginInput = document.querySelector("#login-form input");
const greeting = document.querySelector("#greeting");
const HIDDEN_CLASSNAME = "hidden";
const USERNAME_KEY = "username";
function onLoginSubmit(event) {
event.preventDefault();
loginForm.classList.add("hidden");
loginForm.classList.add(HIDDEN_CLASSNAME);
const username = loginInput.value;
console.log(username);
localStorage.setItem(USERNAME_KEY, username);
paintGreetings();
}
function handleLinkClick(event) {
event.preventDefault();
const username = loginInput.value;
loginForm.classList.add("hidden");
greeting.innerText = "Hello" + username;
function paintGreetings() {
const username = localStorage.getItem(USERNAME_KEY);
greeting.innerText = `Hello ${username}`;
greeting.classList.remove(HIDDEN_CLASSNAME);
}
const savedUsername = localStorage.getItem(USERNAME_KEY);
if(savedUsername === null){
loginForm.classList.remove(HIDDEN_CLASSNAME);
loginForm.addEventListener("submit", onLoginSubmit);
link.addEventListener("click", handleLinkClick);
\ No newline at end of file
}
else{
paintGreetings();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment