Palindrome Project

Hello. Could you please tell me if you find why my code is invalid? Thanks in advance!

Task: 1. 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".

document.getElementById("check-btn").addEventListener("click", function() {
    if(document.getElementById("text-input").value == "") {
      alert("Please input a value");
    }
  });
1 Like

You’re using curly quotes in places you need to use double quotes.

I tried with double quotes, but it didn’t work.

Have you replaced ALL curly quotes with double quotes?

Yes, especially when I’m typing here, the website turned out curly quotes. Normally, it has already been double quotes.

1 Like

in programming, only double quotes are used, also check if your if element has the correct spacing layout as well
[here] C If ... Else Conditions

@isil.ozdemir you need to apply correct spacing in the addEventListener as well,
check this HTML DOM Element addEventListener() Method

I am afraid I didn’t understand the problem.

you have multiple same id elements, id’s are unique.

Could you share your full code with us please, instead of screenshots?
Have you linked to your script.js file in your HTML doc?

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

please share your html too


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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

please stop sharing screenshots, share your code here instead

<input id="text-input" here">
<button id="check-btn" onlick="checkPalindrome()">Click</button>
<div id="result"></div>
<span id="result"></span>
<p id="result"></p>
    if(document.getElementById("text-input").value =="") {
      alert("Please input a value");
    }
  });

type or paste code here

where is the code that links your js file to the html file?

document.getElementById("check-btn").addEventListener("click", function() {
    if(document.getElementById("text-input").value =="") {
      alert("Please input a value");
    }
  });

info about id HTML - The id attribute
info about classes HTML Classes - The Class Attribute
i recommend reading these to understand their difference

can you use your own words please?

that is not the html needed to link the js file, you are missing a script element

1 Like

Isn’t it enough to get the alert via the calling onclick function? It works in this practice.

https://www.w3schools.com/js/tryit.asp?filename=tryjs_addeventlistener_add

the html file and the javascript files are not linked together, the browser reads the HTML file, and if you don’t mention the JS file in the HTML file the browser doesn’t know where to get the JavaScript from

you need to add the script element that links to the script.js file

On some platforms (w3schools, codepen etc) these things are handled in the background for you, but otherwise you should be using a proper HTML boilerplate setup. Your HTML doc should have a head and a body and all of the meta, link and script elements which are routinely required.

Here’s a useful explainer, written by one of the staff here at FCC: