I have noticed an issue with my user input field. Even when I enter a valid genre name, the alert prompt still appears saying it is not a valid genre. This occurs after entering both valid and invalid inputs.
For example, if the user enters "horror," which is a valid input, the alert still shows up indicating that the genre is not valid.
The problem seems to be related to the condition within the if statement where it checks for genre[i].name.
$('#submitButton').click(function(){
reset();
// getting genre from user
let genreSubmission = $('#inputSearch').val().toLowerCase();
let genreId = 0;
// api genre ids objects to change the api link
const genre = [
{
"id": 28,
"name": "Action"
},
...
];
for (let index = 0; index < genre.length; index++) {
if(genreSubmission === genre[index].name.toLowerCase()){
genreId = genre[index].id;
console.log(genreId);
} else{
return alert("not a valid genre");
}
};