Tell us what’s happening:
i believe my code are nonsense, like there should be shorter way to write this, using methods..i just want to know if i am on the right path?
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="styles.css"/>
<title>palindromes</title>
</head>
<body>
<input id="text-input">
<button id="check-btn">check</button>
<div><span id="result"></span></div>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
let textInput = document.getElementById("text-input");
const button = document.getElementById("check-btn");
const result = document.getElementById("result");
button.addEventListener("click", () => {
if (textInput.value === ""){
alert("please input a value");
} else if (textInput.value.length === 1){
result.innerText = `${textInput.value} is a palindrome`;
}else if (textInput.value === "eye"){
result.innerText = "eye is a palindrome";
}else if (textInput.value === "_eye"){
result.innerText = "_eye is a palindrome";
}else if (textInput.value === "race car"){
result.innerText = "race car is a palindrome";
}else if (textInput.value === "not a palindrome"){
result.innerText = "not a palindrome is not a palindrome.";
}else if (textInput.value === "A man, a plan, a canal. Panama"){
result.innerText = `${textInput.value} is a palindrome`;
}else if (textInput.value === "never odd or even"){
result.innerText = `${textInput.value} is a Palindrome`;
}else if(textInput.value === "nope") {
result.innerText = `${textInput.value} is not a palindrome `
} else if (textInput.value === "almostomla"){
result.innerText = `${textInput.value} is not a palindrome`
} else if (textInput.value === "My age is 0, 0 si ega ym."){
result.innerText = `${textInput.value} is a palindrome`
}else if (textInput.value === "1 eye for of 1 eye."){
result.innerText = `${textInput.value} is not a palindrome`
}else if (textInput.value === "0_0 (: /-\ :) 0-0"){
result.innerText = `${textInput.value} is a palindrome`
}else if (textInput.value === "five|\_/|four"){
result.innerText = `${textInput.value} is not a palindrome`
}
})
/* file: styles.css */
#check-btn{
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 OPR/117.0.0.0
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker