Reverse a String with Decremented for loop

Tell us what’s happening:
I am trying to do this with a decremented for loop and it doesn’t seem to be working. What can I do to better understand what is going on in this?

Your code so far

function reverseString(str) {
  let backward = str.split('')
  for (let i = backward.length - 1; i > 0; i--) {
     return backward.join([i])


Remember that when a return statement is executed, the function is exited. You are not really looping because you are returning in the first iteration.

I also think that you need to go look at how join() works. I’m not sure what you expect it to do, but I know that it’s not doing what you want.

1 Like

The solution to this problem is a one-liner, and does not need a loop. I’ll pass on a hint for the method you’re going to need:

1 Like

Other than what ArielLeslie said, if you use i > 0 as condition of the loop, you will never be able to reach the item at index 0

1 Like