Trouble with a reverse count for loop

For this challenge, I was able to get a array sorted out, and checking it shows that the array is there as it should be. However when I tried to implement the for loop, my results did not match what I thought was going to happen.

I’m trying to start from the end of the array and concantenate in reverse. However there is an error in the initialisation of it, and its causing infinite loop errors instead of properly ending at the closing statement.

Is anyone able to see what I have done wrong with the for loop statement?

  **Your code so far**

function reverseString(str) {
let re = /\w/gi;
let arr = str.match(re);
let revStr = "";
for (let i = arr.length - 1; i = 0; i--) {
  revStr += arr[i];
return revStr;

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Reverse a String

Link to the challenge:

What does i = 0 do?

In your for loop i=0 will reassign i to 0 on every loop and it is supposed to be a condition and not an assignment.

thank you, this was a big dumb moment.

We’ve all done it. Welcome to the club :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.