Skip to content

Commit 5787369

Browse files
committed
[Solved issue: #817] : Fixed the issue of checking palindrome.
Changed the logic of checking palindrome in JS file, added button to check and reset.
1 parent 7b05683 commit 5787369

3 files changed

Lines changed: 51 additions & 21 deletions

File tree

Projects/palindrome/palindrome.css

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ html{
1616
h1{
1717
font-size: 2.5rem;
1818
font-family: cursive;
19-
color: rgba(0, 119, 40, 0.452);
19+
color: seagreen;
2020
margin-bottom: 20px;
2121
}
2222

@@ -37,20 +37,27 @@ p{
3737
top: 50%;
3838
left: 50%;
3939
transform: translate(-50%, -50%);
40-
-webkit-text-stroke: 1px rgb(11, 12, 12);
41-
4240
}
4341

4442
#input {
4543
padding: 10px;
4644
width: 450px;
4745
font-size: 0.8rem;
4846
}
49-
47+
.button{
48+
top: 50%;
49+
left: 50%;
50+
width:75px;
51+
transform: translate(-50%, -50%);
52+
-ms-transform: translate(-50%, -50%);
53+
background-color: #f1f1f1;
54+
color: black;
55+
font-size: 16px;
56+
cursor: pointer;
57+
border-radius: 5px;
58+
text-align: center;
59+
}
5060
button:hover {
51-
cursor: pointer;
52-
background-color: white;
53-
font-weight: medium;
54-
box-shadow: 0 0 10px rgb(169, 205, 235);
55-
color: #137570;
61+
background-color: black;
62+
color: white;
5663
}

Projects/palindrome/palindrome.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<link rel="stylesheet" href="palindrome.css">
4+
<link rel="stylesheet" href="palindrome.css" />
55
</head>
66
<body>
77
<div class="image"></div>
88
<div class="text">
99
<h1>PALINDROME CHECKER</h1>
1010
<form>
11-
<input type="text" id="input" name="input" oninput="palindrome_check()" placeholder="Enter a string" autocomplete="off">
11+
<input
12+
type="text"
13+
id="input"
14+
name="input"
15+
placeholder="Enter a string"
16+
autocomplete="off"
17+
/>
1218
</form>
19+
<button type="button" class="button" onclick="palindrome_check()">
20+
Check
21+
</button>
22+
<button type="button" class="button" onclick="reset()">Reset</button>
1323
<p id="prog"></p>
1424
<script src="palindrome.js"></script>
1525
</div>

Projects/palindrome/palindrome.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
function palindrome_check() {
2-
var ishtra = document.getElementById("input").value;
3-
var reg = /[\W_]/g;
4-
var smallstring = ishtra.toLowerCase().replace(reg, "");
5-
var reversed = smallstring.split("").reverse().join("");
6-
if (reversed === smallstring){
7-
document.getElementById("prog").innerHTML = `<b>"${ishtra}"</b> is a palindrome!.`;
1+
function palindrome_check(){
2+
var str1 = document.getElementById("input").value;
3+
var str=str1.replace(/\s/g, "");
4+
if(isPalindrome(str)===true)
5+
document.getElementById("prog").innerHTML = `<b>"${str}"</b> is a palindrome!.`;
6+
else
7+
document.getElementById("prog").innerHTML = `<b>"${str}"</b> is not a palindrome!.`;
8+
}
9+
function isPalindrome(str1) {
10+
str=str1.toLowerCase();
11+
for (let i = 0; i < Math.floor(str.length / 2); i++)
12+
{
13+
var char1=str[i],char2=str[str.length - 1 - i];
14+
if (char1 !== char2)
15+
{
16+
return false;
17+
}
18+
819
}
9-
else {
10-
document.getElementById("prog").innerHTML = `<b>"${ishtra}"</b> is not a palindrome!.`;
11-
}
20+
return true;
21+
}
22+
function reset(){
23+
document.getElementById("input").value="";
24+
document.getElementById("prog").innerHTML="";
1225
}

0 commit comments

Comments
 (0)