The Code for REwind.


                        // Get the string entered
                        function getInput() {
                            document.getElementById("alert").classList.add("invisible");
                        
                            let input = document.getElementById("userString").value;
                        
                            let reversedString = reverseString(input);
                        
                            displayString(reversedString);
                        }
                        
                        // Reverse the string
                        function reverseString(userString) {
                            let reversed = [];
                        
                            //Reverse string using a for loop - Method 1
                            for(let i = 0; i < userString.length; i++) {
                                reversed += userString[(userString.length - 1) - i];
                            }
                        
                            // Reverse string using a for loop - Method 2
                            //for(let i = userString.length - 1; i >= 0; i--) {
                            //    reversed += userString[i];
                            //}
                        
                            return reversed;
                        }
                        
                        // Display the reversed string
                        function displayString(outputString) {
                            //Write message to the page
                            document.getElementById("msg").innerHTML = `Your string reversed is: ${outputString}`;
                        
                            // Show alert box
                            document.getElementById("alert").classList.remove("invisible");
                        }
                        

REwind is a JavaScript coding challenge. We ask the user to enter a string, and then we reverse it.

getInput()

We use the JavaScript document API to get the string entered by the user. Next we call the reverseString() function to reverse the string that the user provided. After that we call the displayString() method to output the result.

reverseString()

We use a for loop to reverse the string that the user entered.

displayString()

We use the JavaScript document API innerHTML property to insert the reversed string onto the page. Then we set the Bootstrap alert to visible so that the message can be seen.