Trying to solve this: Reverse a String

Tell us what’s happening:

My 1st idea was to
convert the string to an array
use a for loop to go through each character over the array
use .pop() /.push() to change each letter to the end
then convert it to a string.
That didn’t seem to work
and I found out about reverse so I tried to implement that
yet it still fails

Your code so far


function reverseString(str) {
 
 //convert the string into an array using split
 //then reverses that array using the reverse

return str.split("").reverse().toString();
//then converts the array to a string again
}

reverseString("hello");





Your browser information:

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

Challenge: Reverse a String

Link to the challenge:

Hello Kora,

This is where your problem is:

.toString();

You are so close to finishing, but .toString() does not take an array, and make it into one string. .toString() is typically used on objects of type number.

This is more what you want: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join

Hope this helps

2 Likes