-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (28 loc) · 856 Bytes
/
index.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
function User(username, timesQuizTaken, lastSong, favorites, history) {
this.username = username;
this.timesQuizTaken = timesQuizTaken || 0;
this.lastSong = lastSong || '';
this.favorites = favorites || [];
this.history = history || {};
}
function createUser(event) {
event.preventDefault();
var userName = event.target.userName.value;
var user = new User(userName);
var strUser = JSON.stringify(user);
localStorage.setItem('User', strUser);
showButton();
}
function showButton() {
var form = document.getElementById('form');
form.style.visibility = 'hidden';
var enter = document.getElementById('enter');
enter.style.visibility = 'visible';
}
(function checkLocalStorage() {
if (localStorage.User) {
showButton();
}
})();
var user = document.getElementById('form');
user.addEventListener('submit', createUser);