Tell us what’s happening:
I’ve tried multiple times for this one question
" When the text-input
element contains the text
_eye
and the
check-btn element is clicked, the result element should contain the text
_eye is a palindrome
"
and by now it should be validated but it’s not pls what do I do
Your code so far
<!-- file: index.html -->
<!-- ~ Palindrome -->
<!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>
</head>
<body>
<main>
<!-- This is where the text is written -->
<input type="text" id="text-input">
<!-- This interacts with the input -->
<button id="check-btn">Check</button>
<div></div>
<!-- This displays the output of the interaction -->
<p id="result"></p>
</main>
</body>
<script src="script.js"></script>
</html>
/* file: script.js */
const textInput = document.getElementById("text-input");
const checkBtn = document.getElementById("check-btn");
const result = document.getElementById("result");
const checkForunderScore = () => {
let valueOfinput = textInput.value.trim();
let splitValue = valueOfinput.split("");
let underscoredValue = [];
// let joinedSplit = splitValue.join("");
for (let i = 0; i < splitValue.length; i++) {
if (splitValue[i] == "_") {
continue;
}
underscoredValue.push(splitValue[i]);
}
let joinedUnderscore = underscoredValue.join('');
let reversedJoined = underscoredValue.reverse().join('');
if(splitValue[0] == '_' && reversedJoined == joinedUnderscore){
return `_${joinedUnderscore} is a palindrome`
}
else if(splitValue[0] == '_' && reversedJoined !== joinedUnderscore){
return `_${joinedUnderscore} is not a palindrome`
}
if(splitValue[0] !== '_' && reversedJoined == joinedUnderscore){
return `${joinedUnderscore} is a palindrome`
}
if(splitValue[0] !== '_' && reversedJoined !== joinedUnderscore){
return `${joinedUnderscore} is not a palindrome`
}
};
checkBtn.onclick = function () {
console.log(checkForunderScore());
};
/* 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/132.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker