-
Notifications
You must be signed in to change notification settings - Fork 0
/
random user.js
29 lines (26 loc) · 1 KB
/
random user.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
import { get, getAll, getUserData } from './random user modules.js'
const URL = 'https://randomuser.me/api/'
const profilePic = get('.profilePic')
const userInfo = get('.userInfo')
const info = get('.info')
const btn = get('.btn')
const icons = [...getAll('.icon')]
window.addEventListener('DOMContentLoaded', placeUserInfo)
btn.addEventListener('click', placeUserInfo)
async function placeUserInfo() {
const values = await getUserData(URL)
profilePic.src = values.profilePic
info.innerText = icons[0].dataset.label
userInfo.innerText = `${values[icons[0].dataset.label]}`
icons.forEach((ev) => ev.classList.remove('changeColor'))
icons[0].classList.add('changeColor')
icons.forEach((e) => {
e.addEventListener('click', () => {
const label = e.dataset.label
info.innerText = label
userInfo.innerText = `${values[label]}`
icons.forEach((ev) => ev.classList.remove('changeColor'))
e.classList.add('changeColor')
})
})
}