I love coding, coding everyday is the dream! This is one of my projects built with ASP.NET MVC, C# and Postgres to share everything I'm learning on my coding journey. Join me and checkout my portfolio to see more of my projects.
A for loop can be used on a string directly to execute code on each character as if it's an array.
CHECK OUT THE APP >> HERE <<!
CODE EXPLANATION
Flip Flop 180 was created with the following three functions.
getValues kicks everything off. When the "Am I Lucky?" button is pressed, it grabs the value of the string from the user by accessing the DOM. It also uses an if-else statement to check if a string was entered. If no string was entered a sweetalert is displayed notifying the user to enter a string. If all is good, it continues to execute reverseMessage and displayMessage.
reverseMessage uses a for loop to reverse the string by grabbing each character from the string starting from the end of the string and adding it to a new variable. The reversed string is then returned.
displayMessage uses getElementById to display the reversed message to the user.
WHAT I LEARNED
- A for loop can be used to loop through a string as if it's an array.
- Everything retrieved from the HTML comes in as a string even if it has a type="number" on the element
IMPROVEMENTS
- Add error if user enters only spaces
- Add some kind of decoration or animation when user enters word(s) from the dictionary that are also words from the dictionary backwards
0 comments