-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolindrome.js
54 lines (40 loc) · 1.37 KB
/
polindrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const textInput = document.querySelector("input");
const checkBtn = document.querySelector("button");
const info = document.querySelector("#info");
checkBtn.addEventListener("click", function() {
let filterText = document.getElementById("text").value;
checkPalindrome(filterText);
});
function checkPalindrome(filterText) {
let text_now = filterText.replace(/[\W_]/g, "") .toLowerCase();
let text_okay = text_now.toLowerCase()
.split("")
.reverse()
.join("");
if(filterText != text_okay) {
info.style.display = "block";
info.innerHTML = `No, <span>'${textInput.value}'</span> isn't a palindrome!`;
} else
return info.innerHTML = `Yes, <span>'${textInput.value}'</span> is a palindrome!`;
}
/*let filterText = " "
checkBtn.addEventListener("click", () => {
let reverseInput = filterText.split("").reverse().join("");
info.style.display = "block";
if(filterText != reverseInput) {
return info.innerHTML = `No, <span>'${textInput.value}'</span> isn't a palindrome!`;
} else
return info.innerHTML = `Yes, <span>'${textInput.value}'</span> is a palindrome!`;
});
function palindrome(str) {
return str.replace(/[\W_]/g, "") .toLowerCase() ===
str.replace(/[\W_]/g, "")
.toLowerCase()
.split("")
.reverse()
.join("")
};
// palindrome("eye");
// console.log(eye);
checkBtn.addEventListener("click", () =>
*/