-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
174 lines (163 loc) · 6.46 KB
/
script.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//var fetch = require('node-fetch');
document.getElementById('myButton').addEventListener('click', fetchData);
document.getElementById('submit').addEventListener('click', fetchSolo);
document.getElementById('submitTeam').addEventListener('click', formParty);
document
.getElementById('submitTeamManual')
.addEventListener('click', submitManual);
async function fetchData() {
const theNumb = Math.floor(Math.random() * 1010);
const res = await fetch('https://pokeapi.co/api/v2/pokemon/' + theNumb, {
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
});
const record = await res.json();
//console.log(JSON.stringify(record));
document.getElementById('thePokemon').innerHTML =
'<img src=' +
record.sprites.front_default +
' style="width: 150px;"></img>';
document.getElementById('theId').innerText = record.id;
let firstName = record.name;
const capName = firstName.charAt(0).toUpperCase() + firstName.slice(1);
document.getElementById('theName').innerText = capName;
let pokeType = record.types[0].type.name;
const capType = pokeType.charAt(0).toUpperCase() + pokeType.slice(1);
document.getElementById('theType').innerText = capType;
document.getElementById('theDes').innerHTML =
'<img src=' + record.sprites.front_shiny + ' style="width: 150px;"></img>';
}
async function fetchSolo() {
const theNumb = document.getElementById('fname').value;
const res = await fetch('https://pokeapi.co/api/v2/pokemon/' + theNumb, {
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
});
const record = await res.json();
//console.log(record);
document.getElementById('thePokemon').innerHTML =
'<img src=' +
record.sprites.front_default +
' style="width: 150px;"></img>';
document.getElementById('theId').innerText = record.id;
let firstName = record.name;
const capName = firstName.charAt(0).toUpperCase() + firstName.slice(1);
document.getElementById('theName').innerText = capName;
let pokeType = record.types[0].type.name;
const capType = pokeType.charAt(0).toUpperCase() + pokeType.slice(1);
document.getElementById('theType').innerText = capType;
document.getElementById('theDes').innerHTML =
'<img src=' + record.sprites.front_shiny + ' style="width: 150px;"></img>';
document.getElementById('thePokemon2').innerHTML =
'<img src=' +
record.sprites.front_default +
' style="width: 150px;"></img>';
document.getElementById('theId2').innerText = record.id;
let firstName2 = record.name;
const capName2 = firstName2.charAt(0).toUpperCase() + firstName2.slice(1);
document.getElementById('theName2').innerText = capName2;
let pokeType2 = record.types[0].type.name;
const capType2 = pokeType2.charAt(0).toUpperCase() + pokeType2.slice(1);
document.getElementById('theType2').innerText = capType;
document.getElementById('theDes2').innerHTML =
'<img src=' + record.sprites.front_shiny + ' style="width: 150px;"></img>';
}
async function submitManual() {
window.location.replace('buildteam.html');
}
async function formParty() {
window.location.replace('generateteam.html');
/*setTimeout(100);
theIndex = 2;
for (i = 0; i < theLength; i++) {
const theNumb = Math.floor(Math.random() * 1281);
const res = await fetch('https://pokeapi.co/api/v2/pokemon/' + theNumb, {
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
});
var table = document.getElementById('myTable2');
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(theIndex);
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
cell1.id = 'cell0' + theIndex;
var cell2 = row.insertCell(1);
cell2.id = 'cell1' + theIndex;
var cell3 = row.insertCell(2);
cell3.id = 'cell2' + theIndex;
var cell4 = row.insertCell(3);
cell4.id = 'cell3' + theIndex;
var cell5 = row.insertCell(4);
cell5.id = 'cell4' + theIndex;
// Add some text to the new cells:
const record = await res.json();
//console.log(record);
cell1.innerHTML =
'<img src=' +
record.sprites.front_default +
' style="width: 150px;"></img>';
cell2.innerText = record.id;
let firstName = record.name;
const capName = firstName.charAt(0).toUpperCase() + firstName.slice(1);
cell3.innerText = capName;
let pokeType = record.types[0].type.name;
const capType = pokeType.charAt(0).toUpperCase() + pokeType.slice(1);
cell4.innerText = capType;
cell5.innerHTML =
'<img src=' +
record.sprites.front_shiny +
' style="width: 150px;"></img>';
theIndex++;
} */
}
/*
async function formParty2() {
theIndex = 2;
for (i = 0; i < theLength; i++) {
const theNumb = Math.floor(Math.random() * 1281);
const res = await fetch('https://pokeapi.co/api/v2/pokemon/' + theNumb, {
headers: {
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
});
var table = document.getElementById('myTable2');
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(theIndex);
row.id = 'row' + theIndex;
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = document.getElementById('cell0' + theIndex);
var cell2 = document.getElementById('cell1' + theIndex);
var cell3 = document.getElementById('cell2' + theIndex);
var cell4 = document.getElementById('cell3' + theIndex);
var cell5 = document.getElementById('cell4' + theIndex);
// Add some text to the new cells:
const record = await res.json();
//console.log(record);
cell1.innerHTML =
'<img src=' +
record.sprites.front_default +
' style="width: 150px;"></img>';
cell2.innerText = record.id;
let firstName = record.name;
const capName = firstName.charAt(0).toUpperCase() + firstName.slice(1);
cell3.innerText = capName;
let pokeType = record.types[0].type.name;
const capType = pokeType.charAt(0).toUpperCase() + pokeType.slice(1);
cell4.innerText = capType;
cell5.innerHTML =
'<img src=' +
record.sprites.front_shiny +
' style="width: 150px;"></img>';
theIndex++;
}
$('#submitTeam').attr('onclick', 'formParty2');
}
*/
fetchData();