I am trying to get data from an API but am having trouble. The layout of the data is as follows:
{
"stats": [{
"base_stat": 45,
"effort": 0,
"stat": {
"name": "hp",
"url": "https://pokeapi.co/api/v2/stat/1/"
}
}]
}
I want to get the "base_stat" number to appear after the "stat" name so I will simply look like this: "Hp: 45" (I want it capitalized also)
The other problem I have is that the title runs through the entire list of names, I want it to be the same name the first modal had.
Here is my code and here is my codepen as this project is too big to put it all here.
Codepen: https://codepen.io/drxl/pen/WNjJQXa
API: https://pokeapi.co/api/v2/pokemon/?limit=150 (original)
https://pokeapi.co/api/v2/pokemon/1/(where the stats are)
What I have tried:
function loadStats(item) {
let url = item.detailsUrl;
return fetch(url).then(function (response) {
return response.json();
}).then(function (details) {
//add details to stats
item.stats = [];
for (var i = 0; i < details.stats.length; i++) {
item.stats.push(details.stats[i].stat.name);
}
item.stats = item.stats.join(': <br>');
item.stats = [];
for (var a = 0; a < details.stats.base_stath; a++) {
item.stats.base_stat.push(details.stats[a].base_stat);
}
}).catch(function (e) {
console.error(e);
});
}