The Code for RADAR


                    
                    
                    function getString(){
                        document.getElementById("alert").classList.add("invisible");
                    
                        let userString = document.getElementById("userString").value;
                    
                        userString = cleanString(userString);
                        
                        let revString = reverseString(userString);
                    
                        let returnObj = checkForPalindrome(userString,revString);
                    
                         displayString(returnObj);
                         
                    }
                    
                    function cleanString(userString){
                    
                        userString = userString.replace(/[^a-zA-Z]/g, "").toLowerCase();
                    
                        return userString;
                    }
                    
                    
                    function checkForPalindrome(userString,revString){
                    
                        let returnObj = {};
                    
                        if(userString == revString){
                            returnObj.msg = "Well done! You entered a palindrome!";
                        } else{
                            returnObj.msg = "Sorry! You did not enter a palindrome!";
                        }
                    
                        returnObj.reversed = revString;
                        return returnObj;
                    }
                    
                    function reverseString(userString){
                     
                        let revString = "";
                    
                        for (let index = userString.length - 1; index >= 0; index--) {
                            
                            revString += userString[index];
                        }
                        return revString;
                    }
                    
                    function displayString(returnObj){
                        document.getElementById("alertHeader").innerHTML = returnObj.msg;
                        document.getElementById("message").innerHTML = `Your string reveresed is: ${returnObj.reversed}`;
                        document.getElementById("alert").classList.remove("invisible");
                    }
                    
                
                

This JavaScript program takes a string as input and checks wether it is the same string in reverse.

getValues()

This function gets the string from the document object model.

cleanString()

This function changes the user string. It makes it lower case and removes spaces and special characters from it.

reverseString()

This function reverses the string using a loop.

checkForPalindrome()

This function checks wether the string is the same in reverse. If it is a palindrome it calls the displayString function.

displayString()

This function sends the string to the document object model.