Hi im working on the palindrome checker project can i cant seem to get steps 9,12,13,15,16 to pass. im not really sure why as it seem to work. some help would be appreciated thanks.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<title>Palindrome checker></title>
</head>
<body>
<h1>Palindome?</h1>
<div class="text-box">
<div>
<p>Enter in text to check for a palindrome:</p>
<input id="text-input">
</input>
<button id="check-btn">Check</button>
</div>
<div id="result">
</div>
<div>
<p>A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
</div>
</div>
<script src="./script.js"></script>
</body>
</html>
const textInput = document.getElementById("text-input");
const checkBtn = document.getElementById("check-btn");
const result = document.getElementById("result");
checkBtn.onclick = alert;
function alert() {
if(textInput.value == "") {
alert("Please input a value");
} else {
palindrome()
}
}
const palindrome = () => {
const newstr = textInput.value.toLowerCase().match(/[a-z0-9]/g).join('')
const compstr = textInput.value.toLowerCase().match(/[a-z0-9]/g).reverse().join('')
if(newstr === compstr) {
result.innerText = `${textInput.value} is a palindrome`
return textInput.value
} else {
result.innerText = `${textInput.value} is not palindrome`
return textInput.value
}
}
1 Like
After fiddling with your code and scratching my head as to why tests wouldn’t pass… it came down to some missing characters in your return string.
Try:
result.innerText = `${textInput.value} is not a palindrome`
I was able to pass the tests with your code after that adjustment.
thanks for the help still wont pass im kinda lost
1 Like
Weird. I copied your html, and script exactly. I put those into the project, and the only text I changed was:
result.innerText = `${textInput.value} is not palindrome`
To:
result.innerText = `${textInput.value} is not a palindrome`
And your code was able to pass all the tests. Try copying your work, and resetting the project.
will do see what happends
dude im a dumbass they were both the same lol
thank for all your help cant believe i did that at this for hours
2 Likes
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.