Tell us what’s happening:
I can’t figure out what i’m doing wrong here, I can only pass the first 3 tests.
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">
</head>
<body>
<input id="text-input"></input>
<button id="check-btn">Check for palidrome</button>
<div id="result"></div>
</body>
<script src="script.js"></script>
<html>
/* file: styles.css */
/* file: script.js */
const input = document.getElementById('text-input');
const button = document.getElementById('check-btn');
const div = document.getElementById('result');
button.addEventListener('click', validInput)
const checkPalindrome = (str) => {
let nonAlphanumeric = /[\w_]/g;
let lowRegStr = str.toLowerCase().replace(nonAlphanumeric, '')
let reverseStr = lowRegStr.split('').reverse().join('');
if (reverseStr === lowRegStr) {
div.innerHTML = `${input} is a palindrome`
} else {
div.innerHTML = `${input} is not a palindrome`
}
}
const validInput = () => {
if (input === ''){
alert('Please input a value');
return;
} else{
checkPalindrome(input);
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker