The Code for Be Kind Rewind.


                        //get the string from the page
                        //controller function
                        function getValue(){
                        
                            document.getElementById("alert").classList.add("invisible");
                        
                            let userString = document.getElementById("userString").value;
                        
                            let revString = reverseString(userString);
                        
                            displayString(revString);
                            
                        }
                        
                        
                        // reverse the string
                        //logic function
                        function reverseString(userString){
                        
                            let revString = [];
                        
                            
                            //reverse a string using a for loop
                            for (let index = userString.length - 1; index >= 0; index--) {
                                revString += userString[index];        
                            }
                        
                            return revString;
                        
                        }
                        //display the reversed string to the user
                        //view function
                        function displayString(revString){
                        
                            //write to the page
                            document.getElementById("msg").innerHTML = `Your string reversed is: ${revString}`;    
                            //show the alert box
                            document.getElementById("alert").classList.remove("invisible");
                        }
                    
                

The Code is structed in three functions

getValue()

This function handles the value, sends it to reverseString(). When it is returned, the result is sent to displayString().

reverseString()

This function takes the argument and does a reverse loop and assigns each posistion to a new array and returns the new array.

displayString()

This function takes the argument and displays it as well as removing the class that controls the visibility of the alert it is using to show the results.