Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

So I’ve seen other posts with a similar error, but none of the suggested solutions seem to work. My code passes all of the requirements, except the 4th. What’s weird though is, when I manually check it in the preview, it returns exactly the required text.

I’m sorry to ask the same question that has come up before . I really don’t see how it’s failing.

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>
    <main>
      <h1>Palindrome Checker</h1>
      <div class="container">
        <form id="palindrome-checker">
          <label for="word-input">Enter your word here:</label>
          <input
            type="string"
            id="text-input"
            placeholder="Is it a palindrome..?"
          />
            <button type="submit" id="check-btn">
              Check your word
            </button>
<div id="result"></div>
    </main>
    <script src="./script.js"></script>
  </body>
</html>
/* file: styles.css */
:root {
  --light-grey: #f5f6f7;
  --dark-blue: #0a0a23;
  --fcc-blue: #1b1b32;
  --light-yellow: #fecc4c;
  --dark-yellow: #feac32;
  --light-pink: #ffadad;
  --dark-red: #850000;
  --light-green: #acd157;
}

body {
  font-family: "Lato", Helvetica, Arial, sans-serif;
  font-size: 18px;
  background-color: var(--fcc-blue);
  color: var(--light-grey);
}

h1 {
  text-align: center;
}

.container {
  width: 90%;
  max-width: 680px;
}

h1,
.container,
.output {
  margin: 20px auto;
}

label,
legend {
  font-weight: bold;
}

.input-container {
  display: flex;
  flex-direction: column;
}

button {
  cursor: pointer;
  text-decoration: none;
  background-color: var(--light-yellow);
  border: 2px solid var(--dark-yellow);
}

button,
input,
select {
  min-height: 24px;
  color: var(--dark-blue);
}

fieldset,
label,
button,
input,
select {
  margin-bottom: 10px;
}

.output {
  border: 2px solid var(--light-grey);
  padding: 10px;
  text-align: center;
}

.hide {
  display: none;
}

.output span {
  font-weight: bold;
  font-size: 1.2em;
}

.surplus {
  color: var(--light-pink);
}

.deficit {
  color: var(--light-green);
}
/* file: script.js */
const form = document.getElementById("palindrome-checker");
const input = document.getElementById("text-input");
const resultDiv = document.getElementById("result");

function palindrome(str) {

  let potPal = str
  .toString()
  .toLowerCase()
  .replace(/\W+/g, "")
  .replace(/-|_/g, "")
  let lapTop = potPal
  .toString()
  .split("")
  .reverse()
  .join("")
  //console.log(potPal)
 // console.log(lapTop)
  if (lapTop === potPal) {
    return `${str} is a palindrome`
  } return `${str} is not a palindrome`
}

form.addEventListener("submit", function (event) {
  event.preventDefault();
const userInput = input.value;
if (userInput === "") {
  resultDiv.textContent = "Please input a value"
  return
}
const resultText = palindrome(userInput);
resultDiv.textContent = resultText;
});

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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 @mulceber and welcome to our community!

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.

You should use the window.alert() method for this.

1 Like
  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.

Please review this user story again.

1 Like

Thank you both for the welcome, and for the help - that worked!

1 Like