Tell us what’s happening:
I am getting a uncaught TypeError: Faled to construct ‘URL’: Invalid URL when I click on my button or in the text box, but from my understanding this error is when you’re calling a URL which I am not doing. Since this happens from just clicking on my project to test I can’t test much further.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Palindrome Checker</title>
<link href="styles.css" rel="stylesheet" />
</head>
<body>
<h1>SHOULDN'T THE WORD FOR PALINDROME BE A PALINDROME?</h1>
<div class="container">
<h2>Enter in text to check for a palindrome</h2>
<a class="input-btn">
<input type="text" id="text-input"></input>
<button id="check-btn">CHECK IT!</button>
</a>
<span id="result"></span>
</div>
<div class="deffinition">
<p>💡 A <a style="font-style:italic"> palindrome</a> is a word or phrase that can be read the same way forwards and backwards, ignoring punctuation,case, and spacing.</p>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
body {
background-color: #030353;
width: 100%;
height: 100%;
}
h1 {
color: white;
text-align: center;
width: 600px;
}
.container {
background-color: white;
width: 300px;
height: 150px;
display: block;
margin: auto;
border: solid, black 3px;
border-radius: 5px;
}
h2 {
color: #030353;
text-align: center;
font-size: 1.25em;
margin: 7px
}
.input-btn {
display: flex;
padding-left: 10px;
margin-top: 10px;
}
.text-input {
border: solid, black, 2px;
}
button {
background: orange;
color: #030353;
font-weight: bold;
border-radius: 5px;
margin-left: 15px
}
.deffinition {
width: 300px;
background: green;
border-radius: 5px;
display: block;
margin: auto;
}
p {
color: yellow;
font-weight: bold;
text-align: center;
font-size: 1.25em;
}
/* file: script.js */
const checkBtn = document.getElementById("check-btn");
const textInput = document.getElementById("text-input");
const result = document.getElementById("result");
function palindrome(string) {
const cleanInput = string.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
const reverse = string.split("").reverse().join("");
const cleanReverse = reverse.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
return cleanReverse === cleanInput
};
checkBtn.addEventListener("click", () => {
const input = textInput.value;
if (input === "") {
return result.innertext = `Please input a value`;
};
if (palindrome(input) === true) {
return result.innertext = `${input} is a palindrome`
} else {
return result.innertext = `${input} is not a palindrome`
};
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker - Build a Palindrome Checker