Build a Palindrome Checker Project - Build a Palindrome Checker

Tell us what’s happening:

I’m working on an alert. The code doesn’t pass. Even though on Codepen everything’s working. But on freecodecamp i don’t even get the alert.

Your code so far

<!-- file: index.html -->
<! DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<title>Palindrome Checker</title>
<link href="styles.css" rel="stylesheet" />
</head>
<body>
<h1>Palindrome Checker</h1>
<h2>Welcome to my Palindrome Checker</h2>
<p>Here you can check your text for palindromness. Just input it in a window below to get the text checked.</p>
<input for="text" id="text-input" />
<div id="result"></div>
<button id="check-btn" type="button">Check</button>

<script>
  </script>
  </body>
  </html>
/* file: styles.css */
body {
  min-height: 100vh;
}
*, ::before, ::after {
  box-sizing: border-box;
}
#text-input {
  display: block;
  margin: auto;
background-color: red;
  width: 300px;
  height: 100px;
  overflow: auto;
  border-top: solid black;
}
#result {
  display: block;
  margin: auto;
background-color: red;
width: 300px;
height: 40px;
overflow: auto;
border-bottom: solid black;
}
#check-btn {
  position: absolute;
  right: 250px;
  bottom: 100px;
}
h1, h2, p {
  text-align: center;
}

/* file: script.js */

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

Your browser information:

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

Challenge Information:

Build a Palindrome Checker Project - Build a Palindrome Checker

  • you don’t need to use the let keyword to declare this variable
  • you can use const like you did with others, because you are not changing the value of it (reassigning it a new value)
    and you should get it outside your function, so other functions can use it later
  • if a variable is declared inside a function, it becomes a local variable scoped to that function only

your if condition needs to check if the value of the input is not empty “”

  • it’s best to use let keyword to declare your variables instead ,this fixes several unusual behaviors with var, here is an article for the reasons why.

https://javascript.plainenglish.io/4-reasons-why-var-is-considered-obsolete-in-modern-javascript-a30296b5f08f

  • also alert() method takes argument (alert message) between parentheses, like this
alert("Please input a value");

happy coding.

you need to link the script element to the script file with the src attribute

1 Like

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