Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I have tried running this code in JSFiddle and it’s working fine but when I try to Run the Tests it does not satisfy the requirements. Please help! Thank you!

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" />
    <link rel="stylesheet" href="styles.css">
    <title>Palindrome Checker</title>
  </head>
  <body>
    <header>Palindrome Checker!</header>
    <hr>
    <p id="intro">Please type a word or phrase to check if they are palindromes!</p>
      <input type="text" id="text-input" placeholder="Please type here..."><br>
        <button type="button" id="check-btn">Check it!</button>
      <p> Are you excited to see it?<br>Here it <strong>comes</strong>!</p>
      <div id="result">
      
      </div>
    </body>
    </html>
/* file: styles.css */
#check-btn {
  margin-top: 10px; 
}
/* file: script.js */
const checkBtn = document.getElementById("check-btn")
const textArea = document.getElementById("text-input")
const results = document.getElementById("result")

checkBtn.addEventListener("click", () => {
const word = textArea.value
  if (word === "") {
  alert('"Please input a value"')
  } else {
  palindromeChecker()
  }
})

function palindromeChecker(words) {
	const word = textArea.value;
  const reverseWord = word.replace(/[\s,|_()\\\/.: -]/g,"").split("").reverse().join("")
  const trueWord = reverseWord.toLowerCase()
  const realityWord = trueWord.split("").reverse().join("")
  if (trueWord !== realityWord) {
  	result.innerHTML = '"' + word + " " + "is not a palindrome" + '"'
  } else {
  	result.innerHTML = '"' + word + " " + "is a palindrome" + '"'
  }
  }


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

the quotes around the expected output indicates it should be a string, the expected output doesn’t include quotes

I modified the relevant portion of the code to eliminate the quotes like so:

if (trueWord !== realityWord) {
result.innerHTML = word + " " + “is not a palindrome”
} else {
result.innerHTML = word + " " + “is a palindrome”
}

The test still does not accept my code to be the answer. I retested it on JSFiddle and it’s working as intended.

I also modified the alert() part of the code to remove the quotation marks.

can you repost your code with those changes?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="styles.css">
    <title>Palindrome Checker</title>
  </head>
  <body>
    <header>Palindrome Checker!</header>
    <hr>
    <p id="intro">Please type a word or phrase to check if they are palindromes!</p>
      <input type="text" id="text-input" placeholder="Please type here..."><br>
        <button type="button" id="check-btn">Check it!</button>
      <p> Are you excited to see it?<br>Here it <strong>comes</strong>!</p>
      <div id="result">
      
      </div>
    </body>
    </html>
const checkBtn = document.getElementById("check-btn")
const textArea = document.getElementById("text-input")
const results = document.getElementById("result")
checkBtn.addEventListener("click", () => {
const word = textArea.value
if (word === "") {
  alert('"Please input a value"')
  } else {
  palindromeChecker()
  }
})
function palindromeChecker(words) {
	const word = textArea.value;
  const reverseWord = word.replace(/[\s,|_()\\\/.: -]/g,"").split("").reverse().join("")
  const trueWord = reverseWord.toLowerCase()
  const realityWord = trueWord.split("").reverse().join("")
  if (trueWord !== realityWord) {
  	result.innerHTML = word + " " + "is not a palindrome"
  } else {
  	result.innerHTML = word + " " + "is a palindrome"
  }
  }

Here it is.

I don’t see where you are including the JS file in your HTML.

You don’t need both sets of quotes here. The string that displays should just be Please input a value.

This is it! Thank you so much!

1 Like