Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

Describe your issue in detail here.

I need some help in proceeding forward with the JavaScript aspect. I have tried multiple methods including this, but it does not seem to be working properly.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Palidrome Checker</title>
    </head>
    <body>
      <h1>Palidrome Checker</h1>
      <p>Enter text to check for a palidrome:</p>
      <input id="text-input">
      <button id="check-btn" onclick="input-btn()">Check</button>
      <div id="result">A palidrone id a word or sentencethat's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</div>
      <script src="script.js"></script>
      </body>
  </html>
/* file: styles.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: red;
}

h1 {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 60px;
}

p {
  text-align: center;
  margin-bottom: 10px;

}

input {
  display: inline-block;
  margin-left: 80px;
  justify-content: space-between;
}

#result {
  text-align: center;
  margin-top: 30px;
}

button {
  background-color: yellow;
  padding: 1px;
  border-radius: 5px;
}




/* file: script.js */
const input = document.querySelector("#text-input");
const button = document.querySelector("#check-btn");
const resultDiv = document.querySelector("#result");


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

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hi Fsg12491! It appears that your button event listener may be mislabeled for the element that you’re attempting to evaluate. As your code stands currently, when your “check” button is clicked, your code is attempting to evaluate whether or not “text-input” is empty. The problem that you’re running into is happening because javascript has stored this value under the name “input” rather than “text-input” (which was the name in your html file). Give this a shot and see if it helps you with your next steps:

button.addEventListener("click", function() {
  if (input.value === "") {
    alert("Please input a value");
  }

Best of luck!

I’m now having another issue. I clicked close on freeCodeCamp’s website for a moment. Now I can’t get back my preview on freeCodeCamps website text editor when I went back to the website

Thank you for you help

I’m a bit confiused. What do you mean that my event listener is mislabeled? Do you have any specific advice on how to correct this?

Tell us what’s happening:

Describe your issue in detail here.
I am really stuck. I have tried multiple methods

Your code so far

const textInput = document.getElementById(“text-input”);
const button = document.getElementById(“check-btn”);
const result = document.getElementById(“result”);

function inputBtn() {
document.querySelector(“#check-btn”).onclick = () => {
const input = document.getElementById(“text-input”).value;

console.log("${input}")
if (input == “”) {
document.getElementById(“result”).innerHTML = “”;
return alert(“Please input a value”)
}
const isPal = checkPalidrome(input.toUpperCase());
}
};

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Palidrome Checker</title>
    </head>
    <body>
      <h1>Palidrome Checker</h1>
      <p>Enter text to check for a palidrome:</p>
      <input id="text-input">
      <button id="check-btn" onclick="inputBtn()">Check</button>
      <div id="result">A palidrone is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</div>
      <script src="script.js"></script>
      </body>
  </html>
/* file: styles.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: red;
}

h1 {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 60px;
}

p {
  text-align: center;
  margin-bottom: 10px;

}

input {
  display: inline-block;
  margin-left: 80px;
  justify-content: space-between;
}

#result {
  text-align: center;
  margin-top: 30px;
}

button {
  background-color: yellow;
  padding: 1px;
  border-radius: 5px;
}




/* file: script.js */
const textInput = document.getElementById("text-input");
const button = document.getElementById("check-btn");
const result = document.getElementById("result");

function inputBtn() {
  document.querySelector("#check-btn").onclick = () => {
  const input = document.getElementById("text-input").value;

  console.log(`"${input}"`)
  if (input == "") {
    document.getElementById("result").innerHTML = "";
    return alert("Please input a value")
  }
  const isPal = checkPalidrome(input.toUpperCase());
}
};

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Sure thing! In the code section in my reply, you’ll notice that I changed the portion of your code that originally read “text-input” and replaced it with “input.value”. This corrects the mislabeling of the element that you wanted to evaluate. I hope this makes more sense.

Thank you for the advice

Tell us what’s happening:

Describe your issue in detail here.
I need some help with the #text-input containing only the letter A and how to return the string A is a palindrome. The next several steps immediately following this are very similar in terms of syntax. I was wondering if someone could give me some specific tips on correcting this issue

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Palindrome Checker</title>
    </head>
    <body>
      <h1>Palindrome Checker</h1>
      <p>Enter text to check for a palindrome:</p>
      <input id="text-input">
      <button id="check-btn" onclick="input-btn()">Check</button>
      <div id="result">A palindrone id a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</div>
      <script src="script.js"></script>
      </body>
  </html>
/* file: styles.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: red;
}

h1 {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 60px;
}

p {
  text-align: center;
  margin-bottom: 10px;

}

input {
  display: inline-block;
  margin-left: 80px;
  justify-content: space-between;
}

#result {
  text-align: center;
  margin-top: 30px;
}

button {
  background-color: yellow;
  padding: 1px;
  border-radius: 5px;
}




/* file: script.js */
const input = document.querySelector("#text-input");
const button = document.querySelector("#check-btn");
const resultDiv = document.querySelector("#result");

button.addEventListener("click", function(){
  if(input.value === "") {
    alert("Please input a value")
  } else if (input.value === "A"){
    alert("A is a palindrone");
  }
})

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

don’t hardcode, make a program that can check any input string, not only those from the tests

the #result element should contain the text "A is a palindrome"

so not an alert, you need to change the content of the required element

What should I change the alert to?

You have learned how to change the text of an element in the practice projects, you need to use that

Thank you so much for your help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.