Skip to content

Commit a14527f

Browse files
authored
Add files via upload
1 parent f974e3c commit a14527f

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Palindrome Checker</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="./styles.css">
8+
</head>
9+
<body>
10+
<main id="container">
11+
<h1 id="headline" >Is it a palindrome?</h1>
12+
<div id="text-container">
13+
<input id="text-input" placeholder="Enter text here">
14+
<button id="check-btn">CHECK</button>
15+
<div id="result"></div>
16+
</div>
17+
18+
</main>
19+
<div id="definition">
20+
<p>A <dfn>palindrome</dfn> is a word or phrase that can be read the same way forwards and backwards, ignoring punctuation, case, and spacing.
21+
</p>
22+
</div>
23+
<script src="./script.js"></script>
24+
</body>
25+
</html>

script.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const checkBtn = document.getElementById("check-btn")
2+
const textInput = document.getElementById("text-input")
3+
const resultContainer = document.getElementById("result")
4+
5+
6+
7+
function checkPal(input) {
8+
//check if there is input
9+
if (input === "") {
10+
alert("Please input a value")
11+
resultContainer.style.display = "none"
12+
return
13+
}
14+
15+
//removes all non alphanumeric and reverses
16+
let cleanedText = input.replace(/[^A-Za-z0-9]/gi, '').toLowerCase();
17+
let reversedText = [...cleanedText].reverse().join("")
18+
19+
//checks if input is palindrome
20+
let result = cleanedText === reversedText ? "is" : "is not"
21+
let resultMsg = `<p><strong>${input}</strong> ${result} a palindrome!</p>`
22+
23+
//displays results
24+
resultContainer.innerHTML = resultMsg
25+
resultContainer.style.display = "block"
26+
}
27+
28+
29+
//gives functionality to check button
30+
checkBtn.addEventListener("click", () => {
31+
checkPal(textInput.value)
32+
textInput.value = ""
33+
})

styles.css

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
flex-direction: column;
5+
align-items: center;
6+
font-family: Tahoma, sans-serif;
7+
background: linear-gradient(45deg, #00A86B, #A8D5BA);
8+
}
9+
#container {
10+
display: flex;
11+
flex-direction: column;
12+
justify-content: center;
13+
text-align: center;
14+
margin-top: 200px;
15+
background-color: 00A86B;
16+
padding: 20px;
17+
border: none;
18+
border-radius: 40px;
19+
width: 400px;
20+
}
21+
#text-container {
22+
display: flex;
23+
flex-direction: column;
24+
align-items: center;
25+
gap: 15px;
26+
}
27+
#definition {
28+
display: flex;
29+
flex-direction: column;
30+
justify-content: center;
31+
text-align: center;
32+
margin-top: 200px;
33+
background-color: 00A86B;
34+
padding: 20px;
35+
border: none;
36+
border-radius: 40px;
37+
width: 400px;
38+
}
39+
#text-input {
40+
padding: 10px;
41+
border: none;
42+
border-radius: 6px;
43+
font-size: 1.2rem;
44+
}
45+
#check-btn {
46+
width: 200px;
47+
padding: 10px;
48+
background-color: #C0FF00;
49+
border: none;
50+
border-radius: 12px;
51+
font-size: 1.3rem;
52+
font-weight: bold;
53+
}
54+
55+
#check-btn:hover {
56+
background-color: #90EE90;
57+
}
58+
#result {
59+
font-size: 1.5rem;
60+
}

0 commit comments

Comments
 (0)