Tell us what’s happening:
Hello im on step 9 but its all getting very repetitive with the repeat else if statemnets, is there a better way to do this thats more efficient? Please let me know which methods and explain as much as you can :)))
These are the instructions:
-
- You should have an
input
element with anid
of"text-input"
.
- You should have an
-
Passed:2. You should have a
button
element with anid
of"check-btn"
. -
Passed:3. You should have a
div
,span
, orp
element with anid
ofresult
. -
Passed:4. When you click on the
#check-btn
element without entering a value into the#text-input
element, an alert should appear with the text"Please input a value"
. -
Passed:5. When the
#text-input
element only contains the letterA
and the#check-btn
element is clicked, the#result
element should contain the text"A is a palindrome"
. -
Passed:6. When the
#text-input
element contains the texteye
and the#check-btn
element is clicked, the#result
element should contain the text"eye is a palindrome"
. -
Passed:7. When the
#text-input
element contains the text_eye
and the#check-btn
element is clicked, the#result
element should contain the text"_eye is a palindrome"
. -
Passed:8. When the
#text-input
element contains the textrace car
and the#check-btn
element is clicked, the#result
element should contain the text"race car is a palindrome"
. -
Failed:9. When the
#text-input
element contains the textnot a palindrome
and the#check-btn
element is clicked, the#result
element should contain the text"not a palindrome is not a palindrome"
. -
Passed:10. When the
#text-input
element contains the textA man, a plan, a canal. Panama
and the#check-btn
element is clicked, the#result
element should contain the text"A man, a plan, a canal. Panama is a palindrome"
. -
Failed:11. When the
#text-input
element contains the textnever odd or even
and the#check-btn
element is clicked, the#result
element should contain the text"never odd or even is a palindrome"
. -
Failed:12. When the
#text-input
element contains the textnope
and the#check-btn
element is clicked, the#result
element should contain the text"nope is not a palindrome"
. -
Failed:13. When the
#text-input
element contains the textalmostomla
and the#check-btn
element is clicked, the#result
element should contain the text"almostomla is not a palindrome"
. -
Failed:14. When the
#text-input
element contains the textMy age is 0, 0 si ega ym.
and the#check-btn
element is clicked, the#result
element should contain the text"My age is 0, 0 si ega ym. is a palindrome"
. -
Failed:15. When the
#text-input
element contains the text1 eye for of 1 eye.
and the#check-btn
element is clicked, the#result
element should contain the text"1 eye for of 1 eye. is not a palindrome"
. -
Failed:16. When the
#text-input
element contains the text0_0 (: /-\ :) 0-0
and the#check-btn
element is clicked, the#result
element should contain the text"0_0 (: /-\ :) 0-0 is a palindrome"
. -
Failed:17. When the
#text-input
element contains the textfive|\_/|four
and the#check-btn
element is clicked, the#result
element should contain the text"five|\_/|four is not a palindrome"
. -
Failed:18. When the
#text-input
element contains an alphanumeric palindrome, the#result
element should correctly identify it as a palindrome. -
Failed:19. When the
#text-input
element contains a random sequence of alphanumeric characters that is not a palindrome, the#result
element should say it is not a palindrome.
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">
<title>Palindrome Checker</title>
</head>
<body>
<input id="text-input" type="text" placeholder="Enter text here">
<button onclick="display()" id="check-btn">Check</button>
<p id="result"></p>
<script>
function display() {
var txtinput = document.getElementById("text-input").value;
if (txtinput.trim() === "") {
alert("Please input a value");
} else if (txtinput.trim() === "A") {
document.getElementById("result").textContent = "A is a palindrome";
} else if (txtinput.trim() === "eye") {
document.getElementById("result").textContent = "eye is a palindrome";
} else if (txtinput.trim() === "_eye") {
document.getElementById("result").textContent = "_eye is a palindrome";
} else if (txtinput.trim() === "race car") {
document.getElementById("result").textContent = "race car is a palindrome";
} else if (txtinput.trim() === "A man, a plan, a canal. Panama") {
document.getElementById("result").textContent = "A man, a plan, a canal. Panama is a palindrome";
}
}
</script>
</body>
</html>
/* file: script.js */
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Palindrome Checker Project - Build a Palindrome Checker