Tell us what’s happening:
Please why is my search input value always an “”?
I queried its element with querySelector and I tried changing its backgroundColor with js and it changed…but the input value is still empty.
I then get it with getElementById I’m still experiencing the same thing …the input value is still an empty string
So I can proceed with my coding .
Please, I need help
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" />
<title>RPG SEARCH PROJECT</title>
<link rel="stylesheet" href="styles.css">
<body>
<header><h1>RPG Creature Search App Project</h1></header>
<input id="search-input" required>
<button id="search-button">Search</button>
<div id="others">
<h2 id="creature-name"><span id="creature-id"></span></h2>
<p id="weight"></p>
<p id="height"></p>
<p id="types"></p>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Base</div>
<div class="sub1b" style="width: 50%">Satats
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">HP:</div>
<div class="sub1b" style="width: 50%"><span id="hp"></span>
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Attack:</div>
<div class="sub1b" style="width: 50%"><span id="attack"></span>
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Defense:</div>
<div class="sub1b" style="width: 50%"><span id="defense"></span>
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Special Attack:</div>
<div class="sub1b" style="width: 50%"><span id="special-attack"></span>
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Special Defense:</div>
<div class="sub1b" style="width: 50%"><span id="special-defense"></span>
</div>
</div>
<div style="display: flex">
<div class="sub1a" style="width: 50%">Speed:</div>
<div class="sub1b" style="width: 50%"><span id="speed"></span>
</div>
</div>
<script src="script.js"></script>
</body>
</head>
</html>
/* file: script.js */
const searchInput = document.getElementById("search-input");
const searchBtn = document.getElementById("search-button");
const creatureName = document.getElementById("creature-name");
const creatureId = document.getElementById("creature-id");
const weight = document.getElementById("weight");
const height = document.getElementById("height");
const types = document.getElementById("types");
const hp = document.getElementById("hp");
const speed = document.getElementById("speed");
const attack = document.getElementById("attack");
const defense = document.getElementById("defense");
const specialAttack = document.getElementById("special-attack");
const specialDefense = document.getElementById("special-defense");
const allValidCreatures = "https://rpg-creature-api.freecodecamp.rocks/api/creatures"
const creatureDetails = "https://rpg-creature-api.freecodecamp.rocks/api/creature/name|id"
const fetchAllValidCreatures = async()=>{
try{
const res = await fetch(allValidCreatures)
const data = await res.json()
}catch(err){
console.log(err)
}
}
fetchAllValidCreatures()
console.log(searchInput.value)
/* file: styles.css */
.sub1a{
padding-left: 2vw;
background-color: rgb(16,78,60);
margin-top: 20px;
color: white;
height: 20px;
padding: 5px;
}
.sub1b{
background-color: rgb(16,78,60);
margin-left: 3vw;
padding-left: 2vw;
margin-top: 20px;
color: white;
padding: 5px;
height: 20px
}
body{
background-color: rgb(15,18,40);
color: rgb(192,192,192)
}
input {
background-color: rgb(192,192,192);
padding: 1.5vw;
margin-top: 10px;
border-radius: 5px;
margin-left: 120px
}
button {
background-color: rgb(10,150,10);
padding: 10px;
color: white;
border-radius: 15px;
}
header{
margin-top: 0px;
}
#creature-id {
margin-left: 5px
}
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 OPR/90.0.0.0
Challenge Information:
Build an RPG Creature Search App Project - Build an RPG Creature Search App
