Hello,
I am stuck at step 20 and 21
Can someone please give a check to my code and tell me what can I do in order to pass final steps?
Thank you in advance!
const creatures = [
{
name: "Pyrolynx",
id: "1",
weight: "42",
height: "32",
hp: "65",
attack: "80",
defense: "50",
specialAttack: "90",
specialDefense: "55",
speed: "100",
types: ["fire"],
},
{
name: "Aquoroc",
id: "2",
weight: "220",
height: "53",
hp: "85",
attack: "90",
defense: "120",
specialAttack: "60",
specialDefense: "70",
speed: "40",
types: ["water", "rock"],
},
];
const searchInput = document.getElementById("search-input");
const searchBtn = document.getElementById("search-button");
// stat elements
const creatureName = document.getElementById("creature-name");
const creatureId = document.getElementById("creature-id");
const weight = document.getElementById("weight");
const height = document.getElementById("height");
const hp = document.getElementById("hp");
const attack = document.getElementById("attack");
const defense = document.getElementById("defense");
const specialAttack = document.getElementById("special-attack");
const specialDefense = document.getElementById("special-defense");
const speed = document.getElementById("speed");
const types = document.getElementById("types");
//Search-button function
searchBtn.addEventListener("click", () => {
console.log("hit");
const value = searchInput.value.trim().toLowerCase(); // trim spaces
types.innerHTML = ""; // clear old types before adding new ones
if (!value) {
alert("Please enter a creature name or ID");
return;
} // Find creature in static data
const creature = creatures.find(
(c) => c.name.toLowerCase() === value || c.id === value
);
if (!creature) {
alert("Creature not found");
// Clear UI
creatureName.innerText = "";
creatureId.innerText = "";
weight.innerText = "";
height.innerText = "";
hp.innerText = "";
attack.innerText = "";
defense.innerText = "";
specialAttack.innerText = "";
specialDefense.innerText = "";
speed.innerText = "";
types.innerHTML = "";
return;
}
// Update UI with creature data
creatureName.innerText = creature.name.toUpperCase();
creatureId.innerText = creature.id;
weight.innerText = creature.weight;
height.innerText = creature.height;
hp.innerText = creature.hp;
attack.innerText = creature.attack;
defense.innerText = creature.defense;
specialAttack.innerText = creature.specialAttack;
specialDefense.innerText = creature.specialDefense;
speed.innerText = creature.speed;
// Populate types
creature.types.forEach((type) => {
const typeElement = document.createElement("span");
typeElement.innerText = type.toUpperCase();
typeElement.classList.add("type-badge", type.toLowerCase());
types.appendChild(typeElement);
});
});