-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreeting.js
44 lines (37 loc) · 989 Bytes
/
greeting.js
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
42
43
44
const form = document.querySelector('.js-form');
const input = form.querySelector('input');
const greeting = document.querySelector('.js-greetings');
const USER_LS = 'currentUser';
saveName = (a) =>{
localStorage.setItem(USER_LS, a);
}
handleSubmit = (event) =>{
event.preventDefault();
//preventDefault() = 이벤트의 기본동작을 막음
const currentValue = input.value;
paintGreetings(currentValue);
saveName(currentValue)
}
askForName = () => {
form.classList.add('showing');
form.addEventListener('submit', handleSubmit)
}
paintGreetings = (a) =>{
form.classList.remove('showing');
greeting.classList.add('showing');
greeting.classList.add('greetingsFade');
greeting.innerText = `Hello ${a}`;
}
loadName = () => {
const currentUser = localStorage.getItem(USER_LS);
if(currentUser === null) {
//로컬 스토리지 데이터가 없을 때
askForName();
}else{
paintGreetings(currentUser);
}
}
init = () =>{
loadName()
}
init()