-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgretting.js
More file actions
44 lines (36 loc) · 942 Bytes
/
gretting.js
File metadata and controls
44 lines (36 loc) · 942 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
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'),
input = form.querySelector('input'),
greeting = document.querySelector('.js-grettings');
const USER_LS = 'user',
SHOWING_CN = 'showing';
function saveName(text){
localStorage.setItem(USER_LS, text);
}
function handleSubmit(event){
event.preventDefault();
const Value = input.value;
paintGreeting(Value);
saveName(Value);
}
function askName(){
form.classList.add(SHOWING_CN);
form.addEventListener('submit', handleSubmit);
}
function paintGreeting(text){
form.classList.remove(SHOWING_CN);
greeting.classList.add(SHOWING_CN);
greeting.innerText = `${text}님 반갑습니다!`;
}
function loadName(){
const user = localStorage.getItem(USER_LS);
if(user !== null){
paintGreeting(user);
}else{
askName();
console.log('유저이름이 없는 뎁쇼')
}
}
function init(){
loadName();
}
init();