Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add javascript Palindrome checker #18

Merged
merged 1 commit into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}