I made the same mistake. Having this up top means that the HTML file has not been loaded. Java is unable to look for the id “check-btn”. Shift script to the bottom before the html closing tag.
For the rest of the code, I would try console-logging every step. For example, to assign a variable to the getElement method (refer to any previous lesson).
Add that to addEventListener, ensure that the button works before proceeding.
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 am trying to use an array to iterate and print out the palindrome words but i run into a road block. am i going about this the wrong way?
document.getElementById("check-btn").addEventListener("click", () =>{
const input = document.getElementById("text-input").value;
if(input === ""){
alert("Please input a value");
} else{
const palindromeList = ["A", "eye",
"_eye",
"race car",
"not a palindrome",
"A man, a plan, a canal. Panama",
"never odd or even",
"nope",
"almostomla",
"My age is 0, 0 si ega ym.",
"1 eye for of 1 eye.",
"0_0 (: /- :) 0-0",
"five|_/|four"];
input === palindromeList;
for (let i =0; i < palindromeList.length; i++){
result.innerHTML = palindromeList + "is a palindrome";
}
}
console.log(input);
})
It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?
To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners
Let us know if you have a question about how to make your code more flexible.