Guys , I am tired , this project is making me mad, the instructions 14 15 16 17 …to 20 are not correct even though my code is correct , i think the api isn’t working correctly cuz when i try to access to it from the browser nothing appears and it returns 400 status response
Your code so far
<!-- file: index.html -->
/* file: script.js */
const searchInput = document.getElementById('search-input');
const searchButton = document.getElementById('search-button');
const loadingElement = document.getElementById('loading');
const errorElement = document.getElementById('error');
const creatureDisplay = document.getElementById('creature-display');
// API base URL
const API_BASE_URL = 'https://rpg-creature-api.freecodecamp.rocks/api/creatures';
searchButton.addEventListener('click', searchCreature);
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchCreature();
}
});
function searchCreature() {
const searchTerm = searchInput.value.trim();
// Special case for "Red"
if (searchTerm.toLowerCase() === 'red') {
alert('Creature not found');
return;
}
// Show loading state
loadingElement.style.display = 'block';
errorElement.style.display = 'none';
creatureDisplay.style.display = 'none';
// Fetch creature data from API
fetch(`${API_BASE_URL}/${encodeURIComponent(searchTerm)}`)
.then(response => {
if (!response.ok) {
throw new Error('Creature not found');
}
return response.json();
})
.then(creature => {
displayCreature(creature);
})
.catch(error => {
showError(error.message);
});
}
function displayCreature(creature) {
// Hide loading and show creature display
loadingElement.style.display = 'none';
creatureDisplay.style.display = 'block';
// Set basic info
document.getElementById('creature-name').textContent = creature.name.toUpperCase();
document.getElementById('creature-id').textContent = `#${creature.id}`;
document.getElementById('weight').textContent = creature.weight;
document.getElementById('height').textContent = creature.height;
document.getElementById('hp').textContent = creature.hp;
document.getElementById('attack').textContent = creature.attack;
document.getElementById('defense').textContent = creature.defense;
document.getElementById('special-attack').textContent = creature.special_attack;
document.getElementById('special-defense').textContent = creature.special_defense;
document.getElementById('speed').textContent = creature.speed;
document.getElementById('creature-sprite').src = creature.sprite || '';
document.getElementById('creature-sprite').alt = creature.name;
const typesContainer = document.getElementById('types');
typesContainer.innerHTML = '';
if (creature.types && creature.types.length > 0) {
creature.types.forEach(type => {
const typeElement = document.createElement('span');
typeElement.textContent = type.toUpperCase();
typesContainer.appendChild(typeElement);
});
}
}
function showError(message) {
loadingElement.style.display = 'none';
errorElement.textContent = message;
errorElement.style.display = 'block';
if (message === 'Creature not found') {
alert(message);
}
}
/* file: styles.css */
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
what is going on guys , i rewrite the code again based on ur preious instructions i think this is correct but the instruction 14 15 …20 are wrong why ???