Tell us what’s happening:
Number 15 on the Palindrome Checker project wants “1 eye for of 1 eye.” to say that it’s not a palindrome… but it is a palindrome? why would the test ask for it to say it’s not a palindrome. All of the other test were cleared.
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>
<div>
<h1>Is it a Palindrome?</h1>
<p>Enter in a text to see if it's a palindrome.</p>
<input id="text-input"></input>
<button id="check-btn">Check</button>
<span id="result"></span>
</div>
<script src="./script.js"></script>
</body>
</html>
/* file: script.js */
const textInput = document.getElementById('text-input');
const checkBtn = document.getElementById('check-btn');
const result = document.getElementById('result');
function clean(str){
const regex = /[0-9\+-\s\_\,\/\.\(\)\:]/g;
let a = str.replace(regex, '');
let b = a.toLowerCase();
return b;
}
function check(str){
for (let i=0 ; i < str.length; i++){
if(str[i]!==str[str.length - i - 1]){
return false;
}
}
return true;
}
function getResult(){
let firstClean = clean(textInput.value);
let output = check(firstClean);
if(textInput.value === ""){
return alert("Please input a value");
}
else if (output === false){
return result.innerHTML= `${textInput.value} is not a palindrome.`;
}
else if (output === true){
return result.innerHTML= `${textInput.value} is a palindrome.`;
}
}
checkBtn.addEventListener ('click', getResult);
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker