-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (33 loc) · 1.07 KB
/
script.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
"use strict";
const textInput = document.getElementById("text-input");
const checkForm = document.getElementById("check-form");
const resultBox = document.getElementById("result");
// Event Listener
// checkForm.addEventListener("submit", check()); => funktioniert nicht ?
const btnCheck = document.getElementById("check-btn");
checkForm.addEventListener("submit", check);
//
function check(e) {
e.preventDefault();
const textValue = textInput.value.replace(/[^a-z0-9]/gi, "").toLowerCase();
const reversedText = textValue
.split("")
.reverse()
.join("")
.replace(/[^a-z0-9]/gi, "")
.toLowerCase();
const checkResult = document.createElement("p");
if (textValue.trim() === "") {
window - alert("Please input a value");
return;
}
if (reversedText === textValue) {
resultBox.innerHTML = "";
checkResult.textContent = `${textInput.value} is a Palindrome`;
resultBox.append(checkResult);
} else {
resultBox.innerHTML = "";
checkResult.textContent = `${textInput.value} is not a Palindrome`;
resultBox.append(checkResult);
}
}