Skip to content

Commit

Permalink
Merge pull request #18 from RajVarsani/palindrome-checker
Browse files Browse the repository at this point in the history
Add javascript Palindrome checker
  • Loading branch information
varunKT001 committed Oct 3, 2022
2 parents f5fc593 + 08ef69b commit e169a73
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions projects/Palindrome-checker/index.html
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h2>Javascript Palindrome Checking Function</h2>
<script src="script.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions projects/Palindrome-checker/script.js
@@ -0,0 +1,19 @@
function palindrome(myString) {
/* remove special characters, spaces and make lowercase*/
var removeChar = myString.replace(/[^A-Z0-9]/gi, "").toLowerCase();

/* reverse removeChar for comparison*/
var checkPalindrome = removeChar.split("").reverse().join("");

/* Check to see if myString is a Palindrome*/
if (removeChar === checkPalindrome) {
document.write("<div>" + myString + " is a Palindrome <div>");
} else {
document.write("<div>" + myString + " is not a Palindrome </div>");
}
}
palindrome('"Oh who was it I saw, oh who?"');
palindrome('"Madam"');
palindrome('"Star Wars"');
palindrome('"2,3,4,3,2"');
palindrome('"7,10,7,8,9"');
3 changes: 3 additions & 0 deletions projects/Palindrome-checker/style.css
@@ -0,0 +1,3 @@
div {
margin-top: 20px;
}

0 comments on commit e169a73

Please sign in to comment.