diff --git a/projects/Palindrome-checker/index.html b/projects/Palindrome-checker/index.html new file mode 100644 index 0000000..ed21646 --- /dev/null +++ b/projects/Palindrome-checker/index.html @@ -0,0 +1,14 @@ + + + + + + + Document + + + +

Javascript Palindrome Checking Function

+ + + diff --git a/projects/Palindrome-checker/script.js b/projects/Palindrome-checker/script.js new file mode 100644 index 0000000..02a5884 --- /dev/null +++ b/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("
" + myString + " is a Palindrome
"); + } else { + document.write("
" + myString + " is not a Palindrome
"); + } +} +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"'); diff --git a/projects/Palindrome-checker/style.css b/projects/Palindrome-checker/style.css new file mode 100644 index 0000000..81ef03a --- /dev/null +++ b/projects/Palindrome-checker/style.css @@ -0,0 +1,3 @@ +div { + margin-top: 20px; +}