forked from KatrinaCloyd/MemoryCardGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (39 loc) · 1.18 KB
/
app.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
import { saveUsers, getUsers, setCurrentUser, findById } from './utils.js';
const form = document.querySelector('form');
form.addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(form);
const currentUser = { name: formData.get('name'), game: formData.get('game') };
const existingUsers = getUsers();
const userInArray = findById(formData.get('name'), existingUsers);
if (!existingUsers.length) {
const user = {
name: formData.get('name'),
levels:
{
easy: [],
medium: [],
hard: [],
}
};
existingUsers.push(user);
saveUsers(existingUsers);
setCurrentUser(currentUser);
} else if (userInArray) {
setCurrentUser(currentUser);
} else {
const user = {
name: formData.get('name'),
levels:
{
easy: [],
medium: [],
hard: [],
}
};
existingUsers.push(user);
saveUsers(existingUsers);
setCurrentUser(currentUser);
}
window.location = './game/index.html';
});