Tell us what’s happening:
Everything appears to be working as the steps indicate, but for some reason I can not see, all tests from #14 onwards are failing and I’m just not sure why. Any help would be greatly appreciated, thank you!
Your code so far
<!-- file: index.html -->
<!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" />
<link
rel="icon"
type="image/png"
href="https://cdn.freecodecamp.org/universal/favicons/favicon.ico"
/>
<title>RPG Creature Search App</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<main>
<img
class="freecodecamp-logo"
src="https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg"
alt="freeCodeCamp Logo"
/>
<h1>RPG Creature Search App</h1>
<div class="container">
<form role="search" id="search-form">
<label for="search-input">Search for Creature Name or ID:</label>
<input type="text" name="creature" id="search-input" required />
<button id="search-button">Search</button>
</form>
<div class="output">
<div class="top-container">
<div class="name-and-id">
<span id="creature-name"></span>
<span id="creature-id"></span>
<div class="size">
<span id="weight"></span>
<span id="height"></span>
</div>
</div>
<div id="types"></div>
</div>
<div class="bottom-container">
<table>
<tr>
<th>Base</th>
<th>Stats</th>
</tr>
<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>Sp. Attack:</td>
<td id="special-attack"></td>
</tr>
<tr>
<td>Sp. Defense:</td>
<td id="special-defense"></td>
</tr>
<tr>
<td>Speed:</td>
<td id="speed" class="speed"></td>
</tr>
</table>
</div>
</div>
</div>
<script src="./script.js"></script>
</main>
</body>
</html>
/* file: styles.css */
/* CSS reset */
*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
}
body {
line-height: 1.5;
}
img {
display: block;
}
/* Project styling */
body {
height: 100vh;
font-family: sans-serif;
background-color: #1b1b32;
color: #0a0a23;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.freecodecamp-logo {
height: 30px;
margin: 25px 0;
}
h1 {
color: #f5f6f7;
font-size: 1.7em;
text-align: center;
}
.container {
width: 325px;
margin: 25px 0;
background-color: #f5f6f7;
border: 1px solid #f5f6f7;
border-radius: 15px;
box-shadow: 10px 10px 0px 0px rgba(223, 220, 220, 0.75);
}
.output,
#search-form {
display: flex;
justify-content: center;
}
#search-form {
flex-wrap: wrap;
margin: 10px 0;
padding: 5px;
border-radius: 8px 8px 0 0;
gap: 10px;
}
label {
align-self: center;
}
#search-input:focus-visible,
#search-button:focus-visible {
outline: 3px solid #198eee;
}
#search-input {
height: 40px;
padding-left: 10px;
width: 200px;
}
#search-button {
padding: 14px 0;
width: 80px;
border-radius: 20px;
text-align: center;
background-color: #7f21ab;
color: #f5f6f7;
border: none;
}
.output {
margin: 10px 0;
padding: 5px;
flex-direction: column;
align-items: center;
}
.top-container,
.bottom-container {
display: flex;
flex-direction: column;
width: 100%;
}
.top-container {
display: flex;
flex-direction: column;
justify-content: space-evenly;
margin-bottom: 10px;
padding: 10px;
background-color: #f0f1f7;
min-height: 200px;
}
.bottom-container {
min-height: 325px;
}
.name-and-id {
height: 28px;
font-size: 1.1em;
text-transform: capitalize;
margin-bottom: 5px;
}
#creature-name,
#special-name {
font-weight: bold;
}
.size,
#special-description {
font-size: 0.85rem;
}
#types {
min-height: 30px;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 5px;
}
.type {
width: 66px;
padding: 5px;
font-size: 0.7rem;
text-align: center;
border-radius: 5px;
background-color: red;
text-transform: uppercase;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
font-size: 1 rem;
color: #f5f6f7;
background-color: #7f21ab;
}
th:nth-child(even),
td:nth-child(even) {
border-left: 5px solid #f5f6f7;
}
tr {
border-bottom: 5px solid #f5f6f7;
}
td,
th {
text-align: center;
padding: 8px;
}
/* Special styling for Creature types */
.normal {
background-color: #b7b7aa;
}
.fire {
background-color: #ff6f52;
}
.water {
background-color: #42a1ff;
}
.electric {
background-color: #fecc33;
}
.grass {
background-color: #78cc55;
}
.ice {
background-color: #66ccfe;
}
.fighting {
background-color: #d3887e;
}
.poison {
background-color: #c68bb7;
}
.ground {
background-color: #dfba52;
}
.flying {
background-color: #8899ff;
}
.psychic {
background-color: #ff66a3;
}
.bug {
background-color: #aabb23;
}
.rock {
background-color: #baaa66;
}
.ghost {
background-color: #9995d0;
}
.dragon {
background-color: #9e93f1;
}
.dark {
background-color: #b59682;
}
.steel {
background-color: #abaabb;
}
.fairy {
background-color: #ed99ed;
}
@media screen and (min-width: 550px) {
h1 {
font-size: 2em;
}
.container {
width: 450px;
}
#search-form,
.top-container,
.bottom-container {
width: 95%;
}
.type {
width: 75px;
}
}
/* file: script.js */
const searchInput = document.querySelector("#search-input");
const searchBtn = document.querySelector("#search-button");
const creatureName = document.querySelector("#creature-name");
const creatureId = document.querySelector("#creature-id");
const creatureWeight = document.querySelector("#weight");
const creatureHeight = document.querySelector("#height");
const creatureTypes = document.querySelector("#types");
const creatureHp = document.querySelector("#hp");
const creatureAttack = document.querySelector("#attack");
const creatureDefense = document.querySelector("#defense");
const creatureSpecialAttack = document.querySelector("#special-attack");
const creatureSpecialDefense = document.querySelector("#special-defense");
const creatureSpeed = document.querySelector("#speed");
const urlSearchTemplate = "https://rpg-creature-api.freecodecamp.rocks/api/creature/";
function resetData() {
creatureName.textContent = "";
creatureId.textContent = "";
creatureWeight.textContent = "";
creatureHeight.textContent = "";
creatureTypes.innerHTML = "";
creatureHp.textContent = "";
creatureAttack.textContent = "";
creatureDefense.textContent = "";
creatureSpecialAttack.textContent = "";
creatureSpecialDefense.textContent = "";
creatureSpeed.textContent = "";
}
async function searchCreature(input) {
try {
const res = await fetch(`${urlSearchTemplate}${input}`);
const data = await res.json();
const { id, name, weight, height, stats, types } = data;
const hp = stats.filter(s => s.name === "hp")[0].base_stat;
const attack = stats.filter(s => s.name === "attack")[0].base_stat;
const defense = stats.filter(s => s.name === "defense")[0].base_stat;
const specialAttack = stats.filter(s => s.name === "special-attack")[0].base_stat;
const specialDefense = stats.filter(s => s.name === "special-defense")[0].base_stat;
const speed = stats.filter(s => s.name === "speed")[0].base_stat;
creatureName.textContent = name.toUpperCase();
creatureId.textContent = `#${id}`;
creatureWeight.textContent = `Weight: ${weight}`;
creatureHeight.textContent = `Height: ${height}`;
types.forEach(({name}) => {
creatureTypes.innerHTML += `<span class="type ${name}">${name}</span>`;
});
creatureHp.textContent = hp;
creatureAttack.textContent = attack;
creatureDefense.textContent = defense;
creatureSpecialAttack.textContent = specialAttack;
creatureSpecialDefense.textContent = specialDefense;
creatureSpeed.textContent = speed;
}
catch (err) {
alert("Creature not found");
}
}
searchBtn.addEventListener("click", () => {
resetData();
searchCreature(searchInput.value)
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build an RPG Creature Search App Project - Build an RPG Creature Search App