The Code for Rotator.


                        function getInput() {

                            document.getElementById("alert").classList.add("invisible");
                            let input = document.getElementById("userString").value;
                        
                            let resultObj = isPalindrome(input);
                        
                            displayResult(resultObj);
                        }
                        
                        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;
                            document.getElementById("alert").classList.remove("invisible");
                        }
                        

Rotator is a JavaScript coding challenge to detect palindromes.

getInput()

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.

preparePhrase()

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

isPalindrome()

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.

displayResults()

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.