Tell us what’s happening:
I am getting the correct output however, the grader is not accepting the input as correct. I previously had the result div also contain the h3 and img elements then only have the p element to try and please the grader. It will not accept any of the tests even though I’ve tested them all on my own and they are working correctly. How can I get the grader to accept my answer?
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" />
<title>Palindrome Checker</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Is it are an am <i><u>Palindrome?</u></i></h1>
<p>If word are same in reverse than in normal than is yes on <i><u>Palindrome!</u></i></p>
<input type="text" id="text-input" />
<button id="check-btn">Check Me!</button>
<!-- I hate the way that the freeCodeCamp grader is strict on the text part of the result-->
<div id="result-div" class="result hide">
<div id="result">
</div>
</div>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
:root {
--background-color: #454545;
--text-color: #e4e4e4;
--correct-color: #90ee90;
--nogo-color: #ee9090;
}
* {
background-color: var(--background-color);
text-align: center;
font-family: Georgia, 'Times New Roman', Times, serif
}
h1, p {
color: var(--text-color);
text-shadow: 1px 1px 2px black;
margin-bottom: 50px;
}
input, button {
background-color: var(--text-color);
}
#result-div {
margin: 50px auto 0px auto;
width: 35vw;
height: 35vh;
border: 5px solid #000000;
border-radius: 10px;
}
.is-palin > *, .is-palin {
background-color: var(--correct-color);
}
.no-palin > *, .no-palin {
background-color: var(--nogo-color);
}
h3 {
font-weight: bold;
font-size: 36px;
margin: 15px auto 5px auto;
}
.p-result {
margin: 5px auto 20px auto;
text-decoration: underline;
font-size: 18px;
}
img {
width: 125px
}
.hide {
display: none;
}
/* file: script.js */
const inputBox = document.getElementById("text-input");
const checkButton = document.getElementById("check-btn");
const resultDiv = document.getElementById("result-div");
checkButton.addEventListener('click', isValidInput);
function isValidInput() {
resultDiv.classList.add('hide');
resultDiv.classList.remove('no-palin');
resultDiv.classList.remove('is-palin');
const dirtyString = inputBox.value;
if (dirtyString === "") {
alert("Please input a value");
return;
}
const cleanString = cleanInputString(dirtyString.toLowerCase());
const result = isPalindrome(cleanString);
if (result) {
displayGo(dirtyString);
} else {
displayNoGo(dirtyString);
}
}
function cleanInputString(str) {
const regex = /[()\\/_\-.,\s]/g;
return str.replace(regex, '');
}
function isPalindrome(string) {
const reversedString = [...string].reverse().join("");
console.log(string);
console.log(reversedString);
return string === reversedString ? true : false;
}
function displayGo(string) {
console.log(`${string} is a palindrome`);
resultDiv.classList.remove('hide');
resultDiv.classList.add('is-palin');
resultDiv.innerHTML = `
<h3>YES</h3>
<div id="result" class="is-palin">
<p class="p-result">${string} is a palindrome.</p>
</div>
<img src="img\\go.png" />
`
}
function displayNoGo(string) {
console.log(`${string} is NOT a palindrome`);
resultDiv.classList.remove('hide');
resultDiv.classList.add('no-palin');
resultDiv.innerHTML = `
<h3>NO</h3>
<div id="result" class="no-palin">
<p class="p-result">${string} is not a palindrome.</p>\
</div>
<img src="img\\nogo.png" />
`;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker