The Code for Rotator.

                        function getInput() {

                            let input = document.getElementById("userString").value;
                            let resultObj = isPalindrome(input);
                        function preparePhrase(input)
                            input = input.toLowerCase(); // Lowercase
                            input = input.replace(/\W/g, ''); // Remove non-alpha
                            return input;
                        function isPalindrome(input) {
                            let resultObj = {};
                            let reversed = preparePhrase(input);
                            let original = reversed;
                            reversed = reversed.split("").reverse().join(""); // Reverse
                            if(reversed == original) {
                                resultObj.msg = "Well Done! You entered a palindrome!";
                                resultObj.isPalindrome = true;
                            else {
                                resultObj.msg = "Sorry! You didn't enter a palindrome!";
                                resultObj.isPalindrome = false;
                            resultObj.reversed = reversed;
                            return resultObj;
                        function displayResult(palindromeObj) {
                            let message = [];
                            if(palindromeObj.isPalindrome) {
                                if(palindromeObj.reversed == "") {
                                    message = "I guess an empty string is a palindrome! "
                            message += `Your phrase reversed is: ${palindromeObj.reversed}`;
                            document.getElementById("resultHeader").innerHTML = palindromeObj.msg;
                            document.getElementById("msg").innerHTML = message;

Rotator is a JavaScript coding challenge to detect palindromes.


Controller function that is called when the button is pressed. Used the JavaScript document API to get the string that the user inputted. It then called isPalindrome() with the user's input. The resulting object is then passed to displayResult() which outputs the results.


converts the parameter to lowercase and strips out any non-alpha characters.


Returns an object representing the entered phrase and wether or not it is a palindrome. It uses preparePhrase() to convert the user's input to lowercase, strip out non-alpha characters. Reverse the prepared input, then builds a result object.


Access the properties of the object returned by isPalindrome() to display a message indicating if the inputted string was a palindrome or not, as well as displaying the reversed input regardless.