-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1021 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
35
36
37
38
39
function renderColor(f,list) {
const color = f.colorName.value
const colorItem = document.createElement('li')
colorItem.textContent = `Favorite Color:`
list.appendChild(colorItem)
const colorDiv = document.createElement('div')
colorDiv.style.backgroundColor = color
colorDiv.style.width = '6rem'
colorDiv.style.height = "3rem"
colorItem.appendChild(colorDiv)
}
function renderListItem(f, text, stat, list) {
const Item = document.createElement('li')
Item.textContent = `${text} ${stat}`
list.appendChild(Item)
}
function renderList(f) {
const stats = document.querySelector('#stats')
const list = document.createElement('ul')
renderListItem(f, "Name:", f.personName.value, list)
renderListItem(f, "Age:", f.personAge.value, list)
renderColor(f,list)
stats.appendChild(list)
}
function handleSubmit(ev) {
ev.preventDefault()
const f = ev.target
renderList(f)
}
const personForm = document.querySelector('#person-form')
personForm.addEventListener('submit', handleSubmit)