I am working on completing the Build a Pokemon search app and can’t seem to solve test case #21: When the #search-input element contains an invalid Pokemon name and the #search-button element is clicked, an alert should appear with the text "Pokémon not found" .
Has anyone been able to solve this? It doesn’t make sense to me because I type red into the search bar and get the correct alert. I also type gibberish (i.e. irfbhbkjbfaj) and get the same result (correct alert messages comes up). I’m getting every indication that it’s working but for some reason this test case isn’t passing.
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.
The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
I am working on completing the Build a Pokemon search app and can’t seem to solve test case #21: When the #search-input element contains an invalid Pokemon name and the #search-button element is clicked, an alert should appear with the text “Pokémon not found” .
It doesn’t make sense to me because I type red into the search bar and get the correct alert. I also type gibberish (i.e. irfbaj) and get the same result (correct alert messages comes up). I’d appreciate any help!
Your code so far
<!-- file: index.html -->
/* file: script.js */
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Pokémon Search App Project - Build a Pokémon Search App
The JavaScript file on freeCodeCamp is called script.js, but you used BuildPokedex.js in your <script> tag.
It will work on your local machine, but you should use the correct file names to work on freeCodeCamp. The same goes for the CSS file.
At the top, you will see the names of all files for HTML, CSS and JavaScript.
For tests, it checks your #pokemon-name and #pokemon-id elements for values like GENGAR and (#94 or 94), but your JavaScript adds Name: and ID: before them.
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I have completed the changes above but I still can’t get test case #21 to pass. For reference, test case #21 says the following, " 21. When the #search-input element contains an invalid Pokemon name and the #search-button element is clicked, an alert should appear with the text "Pokémon not found" ."
You moved it to the global scope, once it’s true , it will never change back to false, because there is no code resetting it to false before the for loop.
You also removed the second condition in the || operator. Now, you’re only checking for the name, but what if the user enters the id instead ?