Project Four

Reverse a String.

I had no idea how to get started until I checked one of the tips and using .reverse. But that returned an array, so then I made a new variable that would be a string and made it with the reversed datapoints individually. This gave me hello and howdy but not the words that aren't 5 letters long. This was the next challenge. I looked at the .join tip and shortened that down. But I realize I need to fix the word array first because it only does five data points. Then I checked the last tip which showed me to split the string and simplify my code. It surpised me when I solved it, but finally I ended up with this code:

Factorialize a Number.

This one was the hardest for me to figure out. I started out trying a while loop, but I had a hard time understanding while loops so I couldn't tell if I was doing it wrong or if it wasn't the right thing to do. I ended up progressing to a switch statement with many variables to represent the math. This too brought me major confusion about the math, so I stopped using the switch and changed to an if/else statement. The tip really didn't help me out too much and actually made me more confused. When I stopped thinking about the math and just focused on getting the if/else statement to act like the while loop I had started with. Here is my final product:

Find the Longest Word.

I split the str into an array of just its words. It seemed obvious to me at this point. But now I had to count up each value of the array. I searched through the index of tasks on freecodecamp until I saw .sort snd got an idea. If I could get the array to sort itself by length, then that would resolve my biggest problem. So I just added .length to the a and b properties to make it organize from largest to smallest. Then using bracket notation, it was easy to find the length of the longest word. This was my result:

Free Code Camp Profile