Tell us what’s happening:
I tried to run the code but nothing happen. Could anyone tell me what I have missed?
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link ref="stylesheet" href="styles.css" />
<title>Palindrome Checker</title>
</head>
<body>
<div class="container">
<h1 class="title">Is it a Palindrome?</h1>
<div class="palindrome-div">
<label for="text-input">Enter in text to check for a palindrome:</label>
<input id="text-input" class="palindrome-input"></input>
<button id="check-btn" class="palindrome-btn">Check</button>
<div id="result" class="palindrome-result">
<p class="user-input"></p>
</div>
</div>
<div class="palindrome-definition-div">
<p class="palindrome-definition">A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.</p>
</div>
</div>
<script src="script.js"></script>
</body>
<html>
/* file: script.js */
const userInput = document.getElementById('text-input');
const checkButton = document.getElementById('check-btn');
const palindromeResult = document.getElementById('result');
const checkText = (userInput) => {
if (userInput === '') {
alert("Please Input a value");
return;
} else {
const firsthalf = userInput.substring(0, Math.floor(userInput.length / 2));
const secondhalf = userInput.substring(ceil(userInput.length / 2), userInput.length);
if (firsthalf === secondhalf) {
palindromeResult.innerText = `${userInput} is a palindrome`;
};
if (firsthalf != secondhalf) {
palindromeResult.innerText = `${userInput} is not a palindrome`
};
};
};
checkButton.addEventListener("click", () => {
checkText(userInput.value);
userInput.value = '';
});
/* file: styles.css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #4747b3;
color: #ffffff;
}
.container {
width: 100%;
min-height: 100vh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.title {
text-align: center;
padding: 15px 0;
font-size: 3rem;
margin-bottom: 30px;
}
.palindrome-div {
width: min(100vw, 450px);
min-height: 200px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 20px;
margin: 10px 0;
background-color: white;
}
label {
color: #0a0a23;
margin-bottom: 20px
}
.palindrome-btn {
width: 100px;
border: none;
padding: 15px;
border-radius: 50px;
background-color: #a7016d;
color: #fff;
cursor: pointer;
}
.palindrome-input {
height: 30px;
width: 250px;
text-align: center;
font-size: 1.2rem;
margin: 10px;
border: none;
border-bottom: 3px solid #a7016d;
}
.palindrome-input:focus {
border-bottom: 3px solid #a7016d;
}
.palindrome-input::placeholder {
text-align: center;
}
.user-input {
font-size: 1.4rem;
margin-top: 10px;
text-align: center;
}
.palindrome-result {
overflow-y: auto;
word-wrap: break-word;
min-height: 50px;
color: black;
}
.palindrome-result.hidden {
display: none;
}
.palindrome-definition-div {
width: min(100vw, 450px);
font-size: 1rem;
min-height: 150px;
background-color: #5a596f;
margin-top: 10px;
padding: 30px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.palindrome-definition {
vertical-align: middle;
text-align: center;
}
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.1.1 Safari/605.1.15
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker