Tell us what’s happening:
I can’t pass the 4th requirement, but I had sent the alert already. Please help
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="style/style.css">
<title>Palindrome Checker</title>
</head>
<body>
<input type="text" id="text-input">
<button id="check-btn"></button>
<div id="result"></div>
<script src="script/script.js"></script>
</body>
</html>
/* file: script.js */
const result = document.getElementById("result")
document.getElementById('check-btn').addEventListener('click', function () {
const textInput = document.getElementById('text-input').value.trim();
if (textInput === '') {
alert("Please input a value");
} else {
const textModified = document.getElementById('text-input').value.replace(/[^a-zA-Z]/g,'')
const textCheck = textModified.toUpperCase().split('')
console.log(textInput);
let textBegin = 0;
let textEnd = textCheck.length - 1;
if (textCheck.length % 2 == 0) {
for (let i = 1; i < (textCheck.length - 1)/2; i++ ) {
if (textCheck[textBegin] == textCheck[textEnd]) {
textBegin++;
textEnd--;
} else {
break;
}
}
} else {
for (let i = 1; i < (textCheck.length)/2; i++ ) {
if (textCheck[textBegin] == textCheck[textEnd]) {
textBegin++;
textEnd--;
} else {
break;
}
}
}
if (textCheck[textBegin] == textCheck[textEnd]) {
result.innerText = `${textInput} is a palindrome`
} else {
result.innerText = `${textInput} is not a palindrome`;
}
}
});
/* 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