Tell us what’s happening:
This lab is tricky. I’m failing tests 7 8 10 11 14 16
Is there something wrong with my regex?
Thank you,
Good day,
Mike
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Palindrome Checker</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input id="text-input">
<hr>
<button id="check-btn">Check for Palindrome</button>
<p id="result"></p>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
/* file: script.js */
const checker = document.getElementById("check-btn");
const userInput = document.getElementById("text-input");
const result = document.getElementById("result");
const regex = /^\W/gi;
const value = userInput.value
checker.addEventListener("click", ()=> {
const input = userInput.value.replace(regex,"").toLowerCase();
const reversed = input.split("").reverse().join("");
if (input===""){
alert("Please input a value");
}
else if (reversed === input){
result.textContent=`${input} is a palindrome`;
} else {
result.textContent=`${input} is not a palindrome`;
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15
Challenge Information:
Build a Palindrome Checker - Build a Palindrome Checker