MCPcopy Index your code
hub / github.com/codemistic/Web-Development / generateHtml

Function generateHtml

Pokedex/script.js:39–185  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

37 .then((pokemons) => generateHtml(pokemons))
38
39const generateHtml = (data) => {
40 console.log(data)
41 data.results.forEach(poke => {
42 let node = create('div')
43 let name = create('span')
44 let img = create('img')
45 node.className = 'pokemon'
46 img.className = 'images'
47 name.innerHTML = 'Name: ' + poke.name.charAt(0).toUpperCase() + poke.name.substring(1)
48
49 fetch(poke.url)
50 .then((dat) => dat.json())
51 .then((pokemon) => {
52 let ID = create('span')
53 ID.className = 'id'
54 ID.innerHTML = '#' + pokemon.id
55 let type = create('span')
56 type.className = 'type'
57 let m = typeset(pokemon.types)
58 type.innerHTML = m
59 append(node, img)
60 append(node, ID)
61 append(node, name)
62 append(node, type)
63 img.src = pokemon.sprites.front_default
64 })
65 document.querySelector('.list').appendChild(node)
66
67 //-----Add divs containing types to pokemon on call-----
68
69 typeset = (x) => {
70 // console.log(x)
71 let p = ''
72 for (let i = 0; i < x.length; i++) {
73 p += `
74 <div class= "types">${x[ i ].type.name.charAt(0).toUpperCase() + x[ i ].type.name.substring(1)}</div>
75 `
76 }
77 // console.log(p)
78 return p
79 }
80 })
81
82 // ------------------to give proper colors to the 'types' divs---------------------
83
84 setTimeout(() => {
85 let t = document.querySelectorAll('.types')
86
87 t.forEach(x => {
88 // console.log(x.textContent)
89 switch (x.textContent) {
90 case 'Grass': {
91 x.style.backgroundColor = '#9bcc50'; break;
92 }
93 case 'Poison': {
94 x.style.backgroundColor = '#b97fc9';
95 x.style.color = '#fff';
96 break;

Callers 1

script.jsFile · 0.85

Calls 2

createFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected