For an exercise I need to use this API : https://raw.githubusercontent.com/Laboratoria/LIM011-data-lovers/master/src/data/potter/potter.json and create an input
where I can type a character's name and it will show below the information that is inside the class in the API, but I do not understand how to.
I think the HTML is ok.
<body>
<h1>Person of the day</h1>
<h2>Choose a character</h2>
<div class="form">
<label for="choose">Choose</label> <br>
<input list="list-people" type="text" name="choose" class="form-control" id="input" placeholder="Write here"/>
<datalist id="list-people">
<option value="Harry Potter">
<option value="Hermione Granger">
<option value="Ron Weasley">
<option value="Draco Malfoy">
<option value="Minerva McGonagall">
</datalist>
<button id="myBtn">Try it</button>
</div>
<section id="character"></section>
</body>
With this code I can only see the actor's name on the console, but not console.log :
const characterDom = document.getElementById('character');
let url = "https://raw.githubusercontent.com/Laboratoria/LIM011-data-lovers/master/src/data/potter/potter.json";
const fetchAll = url => {
fetch(url)
.then((res) => res.json())
.then(data => {
const result = data;
console.log(result)
document.getElementById("myBtn").addEventListener("click", displayName);
function displayName() {
document.getElementById("input").innerHTML = `$(actor.name[0])`;
for (let actor of result) {
console.log(actor.name);
if (actor.name == document.getElementById("input").value) {
}
}
}
})
.catch((error) => {
console.error(error);
});
}
fetchAll(url)