Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

what is wrong with my code? it says that When you click on the #check-btn element without entering a value into the #text-input element, an alert should appear with the text Please input a value.

Your code so far

<!-- file: index.html -->
<input id="text-input"></input>
<button id="check-btn"></button>
<div id="result">
</div>
/* file: script.js */
const textInput = document.getElementById("text-input")
const checkButton = document.getElementById("check-btn")
const result = document.getElementById("result")


function palindrome (str){
if (str === ""){
  return alert("Please input a value")
}
}
palindrome()




/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

Hi @random.one and welcome to our community!

You are calling palindrome() with no argument, so what value will str have inside your function?

you mean calling string value as an argument?

Your function expects a string as an argument, so if you call the function without an argument what value will str have inside your function? (Try logging str to the console inside your function to see).

i try this palindrome(str) but is still didnt get the answer

Does str have any value? Log it to the console first.

When you define a function with parameters, those parameters have no inherent value. You give them a value when you call the function with arguments.

EXAMPLE:

// function parameters are num1 and num2
function addTwoNumbers(num1, num2) {
  return num1 + num2;
}

// call the function by supplying arguments to the function parameters
addTwoNumbers(2, 3)
// returns 5

no, it doesnt have any value

if i try palindrome(“eye”) or palindrome(“”) or maybe another string value. it contains value of string but, it still didnt work

If you call palindrome("") with the code you have above, it should trigger an alert. What isn’t working for you?

What doesn’t work, exactly? What happens?

You need to write code to link the button element to your function.

I have to link the function palindrome into check-button, isn’t it

i rewrite my code like this:
function palindrome (str){

if (str === “”){

return alert(“Please input a value”)

}

}

checkButton.addEventListener(“click”, ()=>{palindrome(“”)})

you do not need to do all that to just call a function for testing, you can just write palindrome("") and observe what happens

could you give me resource to read about this before i continue my own code?

about what specifically?

you can consider doing the Full Stack Curriculum if this course is not helping you, it is much more in depth https://www.freecodecamp.org/learn/full-stack-developer/

1 Like

You can call the function (as you were doing) to test it as you build your project. Or, you can test the function by linking the button and function and then entering values directly into the HTML input.

You do have to link the button anyway to complete the project, so you might as well do it now. However, you probably want to add a reference to the function there, rather than calling the function directly with a value. Inside your function you can then get the value from the input element and do what you need to with it.

MORE INFO: