Reverse a String -- should pass?

Seriously?!

It DOES do that

look at the output.

So why is that code showing as doing what it’s supposed to in a code pad but not passing?

  **Your code so far**

function reverseString(str) {

let reversed = [];

for (let i = (str.length - 1); i >= 0; i--) {
  reversed.push(str[i]);
}

str = reversed.toString();

return str;
}

reverseString("hello");
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Reverse a String

Link to the challenge:

Where are those commas coming from?

Calling toString() on an array.

2 Likes

You are using the default toString method. See if you can research how to convert an array to a string in JS. There is a way that gives you more control.

2 Likes

thanks. I appreciate that

Nailed it!

https://onecompiler.com/javascript/3xteupkpj