We will build the Hero Page for the Dota application. Here’s an example of what it looks like:
We’ll eventually combine this page with the Heroes List Page to make a full application. For now, let’s be patient and do one thing at a time.
Please use the Starter file given to you in this lesson. We’ll write the HTML in a file called hero.html and the JavaScript in a file called hero.js.
Please also navigate to /hero.html in your browser to view this page.
Anatomy of the Hero Page
The Hero Page contains 4 pieces of information:
The hero’s name
The hero’s image
The hero’s description
The hero’s abilities
For now, let’s say we want to fetch information about the hero Axe. We’ll set heroName to be axe.
const heroName = 'axe'
We can get the hero’s image via the heroes endpoint.
Getting the hero’s description and abilities are slightly tougher. After digging around the API, I realized we can also get them through the constants repository.
Getting the hero’s description
The hero’s description can be found in hero_lore.json .
If you click on hero_lore.json, you should see an object. This object contains hero names as keys and the description of each hero as values.
To access hero_lore.json, we can use the constants API.
We can get Axe’s abilities by looking under npc_dota_hero_axe.
Axe has 4 abilities:
Beserker’s call
Battle Hunger
Counter Helix
Culling blade
Note: Ignore the generic_hidden portion. It’s not part of a hero’s abilities and I have no idea why it’s in the data. Since it’s in the data, we simply have to deal with it.
If you click on abilities.json you’ll get to a page that “says we can’t show files that are this big right now”.
Don’t worry about this. Click on view raw and you’ll see a list of all the abilities that exist in Dota.
Each entry in this JSON file contains the name, image, and description of the ability. Here’s an example of Axe’s first ability, berserker’s call.
Each item in this mapped list contains the three pieces of information we need. Here’s an example of what we have about Berserker’s Call.
This step is optional. I like to format othe data from the endpoint so I create a map that contains only the data I need. This makes my life slightly easier so I don’t have to remember the dname property when I search for the ability’s name.
It can be quite weird to see the empty Abilities section when there’s no content. We can hide this by adding a hidden attribute to the section initially.