-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathapp.js
32 lines (27 loc) · 966 Bytes
/
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
const { generateText, createElement, validateInput } = require('./util');
const initApp = () => {
// Initializes the app, registers the button click listener
const newUserButton = document.querySelector('#btnAddUser');
newUserButton.addEventListener('click', addUser);
};
const addUser = () => {
// Fetches the user input, creates a new HTML element based on it
// and appends the element to the DOM
const newUserNameInput = document.querySelector('input#name');
const newUserAgeInput = document.querySelector('input#age');
if (
!validateInput(newUserNameInput.value, true, false) ||
!validateInput(newUserAgeInput.value, false, true)
) {
return;
}
const userList = document.querySelector('.user-list');
const outputText = generateText(
newUserNameInput.value,
newUserAgeInput.value
);
const element = createElement('li', outputText, 'user-item');
userList.appendChild(element);
};
// Start the app!
initApp();