-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasterFn.js
More file actions
39 lines (37 loc) · 1.24 KB
/
masterFn.js
File metadata and controls
39 lines (37 loc) · 1.24 KB
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
const superFetchFunction = async (endpoint)=> {
const url = `https://jsonplaceholder.typicode.com/${endpoint}`;
const data = await fetch(url);
const fdata = await data.json()
return fdata
}
const createDom =(data, div,endpoint) =>{
const anoth = (key,value)=>{
console.log(key,value)
}
switch(endpoint){
case 'users':
Object.entries(data).map(([key,value])=> {
// value is an object then create a div tag
if(typeof value !=='object') {
const p = document.createElement("p");
p.setAttribute('class', key)
p.textContent = value;
div.appendChild(p)
anoth(key,value)
} else {
// anoth(key,value)
Object.entries(value).map(([k,v])=> {
// if statements
})
}
})
break;
}
}
const superRenderToDOMFunction =async (endpoint)=>{
const data = await superFetchFunction(endpoint);
const body = document.querySelector('body');
const div = document.createElement("div");
body.appendChild(div);
data.map(a=>createDom(a,div, endpoint));
}