Build a Pokémon Search App Project

Hello. I made a Pokemon Search App code. I just follow all the user stories, especially the user stories from 14-20, but did not pass when I ran the tests. Is there any errors in my javascript code?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Pokémon Search App</title>
    <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
<h1>Pokémon Search App</h1>
<main>
        <div class="pokemon-form">
          <label for="Pokemon">Enter the Pokemon name or ID:</label>
<input id="search-input" type="text" name="pokemon" value="" required />
<button type="button" id="search-button">Search</button>
</div>
<div class="pokemon-container">
<div class="pokemon-name-id">
<span id="pokemon-name"></span>
<span id="pokemon-id"></span>
</div>
<div class="pokemon-size">
<span id="weight"></span>
<span id="height"></span>
</div>

<div id="sprite-img"></div>
  <p id="types"></p>
  </div>

  <table class="pokemon-table">
    <thead>
      <tr>
        <th>Base</th>
        <th>Stats</th>
        </tr>
      </thead>
      <tbody>
        <tr>
        <td>HP:</td>
        <td id="hp"></td>
        </tr>
        <tr>
        <td>Attack:</td>
        <td id="attack"></td>
        </tr>
        <tr>
        <td>Defense:</td>
        <td id="defense"></td>
        </tr>
        <tr>
        <td>Special Attack:</td>
        <td id="special-attack"></td>
        </tr>
        <tr>
        <td>Special Defense:</td>
        <td id="special-defense"></td>
        </tr>
        <tr>
        <td>Speed:</td>
        <td id="speed"></td>
        </tr>
        </tbody>
  </table>
</main>
<script src="script.js"></script>
</body>
</html>

const searchInput = document.getElementById("search-input");
const searchButton = document.getElementById("search-button");
const pokemonName = document.getElementById("pokemon-name");
const pokemonId = document.getElementById("pokemon-id");
const pokemonWeight = document.getElementById("weight");
const pokemonHeight = document.getElementById("height");
const pokemonTypes = document.getElementById("types");
const pokemonSprites = document.getElementById("sprite-img");
const pokemonSprite = document.getElementById("sprite");
const pokemonHp = document.getElementById("hp");
const pokemonAttack = document.getElementById("attack");
const pokemonDefense = document.getElementById("defense");
const pokemonSpAttack = document.getElementById("special-attack");
const pokemonSpDefense = document.getElementById("special-defense");
const pokemonSpeed = document.getElementById("speed");

const pokemonSearch = () =>{
 const pokeValue = searchInput.value.toLowerCase(); 
 const pokeurl = `https://pokeapi-proxy.freecodecamp.rocks/api/pokemon/${pokeValue}`;
fetch(pokeurl)
.then(response => response.json())
.then(data => {
    pokemonName.textContent = data.name.toUpperCase();
    pokemonId.textContent = `#${data.id}`;
    pokemonWeight.textContent = `Weight: ${data.weight}`;
    pokemonHeight.textContent = `Height: ${data.height}`;
    pokemonHp.textContent = data.stats[0].base_stat;
    pokemonAttack.textContent = data.stats[1].base_stat;
    pokemonDefense.textContent = data.stats[2].base_stat;
    pokemonSpAttack.textContent = data.stats[3].base_stat;
    pokemonSpDefense.textContent = data.stats[4].base_stat;
    pokemonSpeed.textContent = data.stats[5].base_stat;
   pokemonTypes.innerHTML = "";
    data.types.forEach((type) => {
    pokemonTypes.innerHTML += `<span>${type.type.name.toUpperCase()}</span>`;
    });
    let sprite = document.createElement("img");
    sprite.src = data.sprites.front_default;
    sprite.id = "sprite";
    pokemonSprites.innerHTML = "";
    pokemonSprites.appendChild(sprite);
}).catch(error => {
    console.log(error);
    resetPokemonData();
    alert("Pokémon not found");    
})
};
const resetPokemonData = () => {
    if(pokemonSprite){
        pokemonSprite.remove();
    }
    pokemonName.textContent = "";
    pokemonId.textContent = "";
    pokemonWeight.textContent = "";
    pokemonHeight.textContent = "";
    pokemonHp.textContent = "";
    pokemonAttack.textContent = "";
    pokemonDefense.textContent = "";
    pokemonSpAttack.textContent = "";
    pokemonSpDefense.textContent = "";
    pokemonSpeed.textContent = "";
    pokemonTypes.textContent = "";
    pokemonSprites.innerHTML = "";
}
searchButton.addEventListener("click",pokemonSearch);

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

I tried all these steps you’ve given but still have the same errors. I also don’t have any extensions. But what browser are you using to work my code?

I ran your code in Chrome and Firefox, and it passes in both.

What tests are failing?

Do you see any errors in the console?

I am using Chrome too. But the tests were failed from 14-20 in the user stories and the console appears ‘Test timed out’ in each user story. By the way, I already made a CSS for this.

Did you link to the script correctly at the bottom of the HTML? It must be named script.js

  <script src="script.js"></script>
</body>

That is how it is in the code you posted, so I assume so.


It is all the JS tests that looks to be failing. So either you didn’t add/load the JS correctly or you are somehow blocking it.

As said, there is nothing wrong with your code, and it is passing all the tests, so clearly it is something else.

What does it mean “Do you link to the script correctly at the bottom of the HTML? It must be named script.js.” But I’m not blocking something else. I just don’t know why my tests are failed even my code is correct.

Even without any JS code, the tests should not be timing out.

Open the browser console and look for errors when you submit. Do the same in the network tab. You will see two 404 (Not Found) that are expected and not errors.


Try in a different browser and try it on a different system as well if you can.

Good day. I tried to ran the tests of my Pokemon Search App project in both Chrome and Mozilla browsers, as well as in incognito, but it still the same. My tests still did not passed and and the console still appeared ‘Test timed out’.

Did you look in the browser dev tools?

As said, there is nothing wrong with the code you posted, and the timeout is likely network related.

You can try using the real API instead of the proxy to see if the proxy is the issue for you (maybe your network is blocking URLs with proxy in them).

https://pokeapi.co/api/v2/pokemon

You can also try using a VPN and/or a public DNS.

Good day. I open my Pokemon Search App project again and I just refreshed it. After I refreshed the page, I tried to ran the tests and it works! I passed all the tests and I have completed all projects in the Javascript Beta and finally, I’ve earned my certification. Thanks you so much. :+1:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.