Tell us what’s happening:
Hello i have a problem in the last 2 test 20 and 21 in RPG Creature app
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RPG Creature Search App</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap" rel="stylesheet">
</head>
<body>
<img src="https://i.imgur.com/jqe4DD9.png" alt="RPG Creature Search App Logo" class="logo">
<h1>RPG Creature Search App</h1>
<div class="main-container" id="cont-1">
<p class="instructions" id="search-instructions">Search for Creature Name or ID:</p>
<div class="secondary-container" id="cont-1_5">
<form>
<input type="text" class="search" id="search-input" required>
<button class="search-btn" id="search-button">Search</button>
</form>
</div>
<div class="secondary-container" id="cont-2">
<div class="secondary-container" id="cont-2_5">
<p class="creature-gen" id="creature-name">Name</p><p class="creature-gen" id="creature-id">#ID</p>
<p class="creature-size" id="weight">Weight: </p><p class="creature-size" id="height">Height: </p>
<span id="types"></span>
</div>
<p class="moves" id="move-name">Move Name</p>
<p class="moves" id="move-info">Move info</p>
</div>
<div class="secondary-container" id="cont-3">
<span class="base" id="base-label">Base</span><span class="stats" id="stats-label">Stats</span>
<span class="base" id="hp">HP</span><span class="stats" id="hp-stats">?</span>
<span class="base" id="attack">Attack</span><span class="stats" id="attack-stats">?</span>
<span class="base" id="defense">Defense</span><span class="stats" id="defense-stats">?</span>
<span class="base" id="special-attack">Sp. Attack</span><span class="stats" id="special-attack-stats">?</span>
<span class="base" id="special-defense">Sp. Defense</span><span class="stats" id="special-defense-stats">?</span>
<span class="base" id="speed">Speed</span><span class="stats" id="speed-stats">?</span>
</div>
</div>
<br>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
const input = document.getElementById("search-input");
const searchBtn = document.getElementById("search-button");
const randomBtn = document.getElementById("random-button");
const clearBtn = document.getElementById("clear-button");
const nameEl = document.getElementById("creature-name");
const idEl = document.getElementById("creature-id");
const weightEl = document.getElementById("weight");
const heightEl = document.getElementById("height");
const hpEl = document.getElementById("hp");
const attackEl = document.getElementById("attack");
const defenseEl = document.getElementById("defense");
const spAttackEl = document.getElementById("special-attack");
const spDefenseEl = document.getElementById("special-defense");
const speedEl = document.getElementById("speed");
const typesEl = document.getElementById("types");
// 📌 Créatures définies par FreeCodeCamp
const creatures = {
"pyrolynx": {
name: "PYROLYNX",
id: 1,
weight: 42,
height: 32,
stats: [65, 80, 50, 90, 55, 100], // hp, atk, def, spAtk, spDef, speed
types: ["FIRE"]
},
"aquoroc": {
name: "AQUOROC",
id: 2,
weight: 220,
height: 53,
stats: [85, 90, 120, 60, 70, 40],
types: ["WATER", "ROCK"]
}
};
// 🔹 Affiche une créature
function displayCreature(creature) {
nameEl.textContent = creature.name;
idEl.textContent = `#${creature.id}`;
weightEl.textContent = `Weight: ${creature.weight}`;
heightEl.textContent = `Height: ${creature.height}`;
hpEl.textContent = creature.stats[0];
attackEl.textContent = creature.stats[1];
defenseEl.textContent = creature.stats[2];
spAttackEl.textContent = creature.stats[3];
spDefenseEl.textContent = creature.stats[4];
speedEl.textContent = creature.stats[5];
// 🔹 Nettoyer et ajouter les types
typesEl.innerHTML = "";
creature.types.forEach(t => {
const span = document.createElement("span");
span.textContent = t;
typesEl.appendChild(span);
});
}
// 🔹 Recherche par nom ou id
function searchCreature(query) {
const key = query.toLowerCase();
if (creatures[key]) {
displayCreature(creatures[key]);
} else if (query === "1") {
displayCreature(creatures["pyrolynx"]);
} else if (query === "2") {
displayCreature(creatures["aquoroc"]);
} else {
alert("Creature not found");
}
}
// 🎯 Listeners
searchBtn.addEventListener("click", () => {
if (input.value.trim() !== "") {
searchCreature(input.value.trim());
}
});
clearBtn.addEventListener("click", () => {
input.value = "";
nameEl.textContent = "";
idEl.textContent = "";
weightEl.textContent = "";
heightEl.textContent = "";
hpEl.textContent = "";
attackEl.textContent = "";
defenseEl.textContent = "";
spAttackEl.textContent = "";
spDefenseEl.textContent = "";
speedEl.textContent = "";
typesEl.innerHTML = "";
});
randomBtn.addEventListener("click", () => {
const keys = Object.keys(creatures);
const rand = keys[Math.floor(Math.random() * keys.length)];
displayCreature(creatures[rand]);
});
/* file: styles.css *//* ====== GENERALI ====== */
body {
background-color: #1B1B32;
margin: 0;
font-family: 'Roboto', sans-serif;
}
.logo {
max-width: 8%;
height: auto;
display: block;
margin: 0 auto;
padding-top: 0.75rem;
}
h1 {
color: white;
text-align: center;
font-family: "Courier", sans-serif;
font-size: 2rem;
font-weight: bold;
}
/* ====== CONTENITORI PRINCIPALI ====== */
#cont-1 {
margin: 0 auto;
background-color: #F5F6F7;
width: 33vw;
height: 108vh;
border-radius: 15px;
box-shadow: 10px 10px 0px #AEACB2;
padding-bottom:20px;
}
#cont-1_5 {
display: flex;
justify-content: center;
align-items: center;
width: 31vw;
margin: 0 auto;
}
/* ====== INPUT E BUTTON ====== */
input {
width: 180px;
height: 35px;
font-size: 0.8rem;
padding-left: 5px;
margin: 0 10px;
}
input:focus {
outline: 2px solid #198EEE;
}
button {
color: white;
background-color: #7F21AB;
border: none;
width: 80px;
height: 40px;
border-radius: 18px;
cursor: pointer;
}
/* ====== ISTRUZIONI ====== */
.instructions {
font-size: 1.1rem;
font-weight: bold;
text-align: center;
padding-top: 15px;
}
/* ====== CONTENUTO CREATURE ====== */
#cont-2 {
margin: 25px auto 10px auto;
background-color: #F0F1F7;
width: 30vw;
height: 34vh;
padding: 10px;
border-radius: 10px;
}
#cont-2_5 {
width: 11vw;
height: 10vh;
margin: 10px auto 50px 1px;
}
/* ====== INFORMAZIONI CREATURE ====== */
.creature-gen {
display: inline-flex;
font-size: 0.9rem;
font-family:"Arial",sans-serif;
font-weight: bold;
margin: 10px 0 5px 3px;
white-space: nowrap;
}
#creature-id {
white-space: nowrap;
font-weight:normal;
font-size:0.8rem;
padding-left:5px;
}
.creature-size {
display: inline;
font-size: 0.8rem;
font-weight: normal;
margin: 5px 2px 0 5px;
white-space: nowrap;
}
#creature-id {
font-weight: bold;
font-size: 0.7rem;
margin-top: 2px;
}
/* ====== TYPES ====== */
#types {
display: inline-flex;
gap: 8px;
margin: 10px -5px 40px 5px;
padding: 4px;
white-space: nowrap;
}
#types span {
padding: 4px 10px;
margin-bottom:10px;
margin-left:-5px;
border-radius: 5px;
color: white;
font-weight: bold;
font-size: 0.8rem;
white-space: nowrap;
background-color: grey; /* fallback */
}
/* ====== MOSSE ====== */
.moves {
margin-left: 9px;
display: flex;
flex-direction: column;
font-family: 'Arial', sans-serif;
}
#move-name {
font-size: 0.9rem;
font-weight: bold;
margin: 60px 0px 5px 9px;
display: block;
}
#move-info {
font-size: 0.85rem;
margin-bottom: 15px;
}
/* ====== STATISTICHE ====== */
#cont-3 {
width: 32vw;
margin: 15px auto 0 auto;
}
.base,
.stats {
display: inline-flex;
justify-content: center;
align-items: center;
background-color: #7F21AB;
color: white;
font-size: 1rem;
font-weight: bold;
text-align: center;
height: 40px;
width:auto;
font-family: 'Roboto', sans-serif;
}
.base {
width: 60%;
margin: 0 0 5px 15px;
}
.stats {
width: 30%;
margin: 0 0 5px 5px;
}
#base-label,
#stats-label {
font-size: 1.3rem;
font-family: "Arial", sans-serif;
font-weight: bold;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build an RPG Creature Search App Project - Build an RPG Creature Search App

