Reverse a String - Can someone take a look

Reverse a String - Can someone take a look
0

#1

Hey!

Can someone take a look at my code here, I am getting the proper output data type as well the string output is reversed but I am not getting my precious green check boxes.

Can someone take a look at the below and let me know what is the issue:

var string=[];
function reverseString(str) {
for(i=0;i<str.length;i++){
string.push((str.charAt(i)));
}
string=string.reverse();
string=string.join("");
return String(string);
}

reverseString(“Hello”);


#2

I think you’re making it a bit complex buddy.

Just make str equal to str split reversed and joined back together again. You can do it all on one line by method chaining. Check out my profile if you want. I always comment stuff so I remember how I did it. No need for the for loop at the beginning.


#3

thats so complex for such a trivia task

var string= "hello";
string=string.split().reverse().join('');


#4

haha thanks OMahonyD & zealsham! I may have overdone it there. Any clue why my way wouldn’t work? Or is this section meant to be done in as few lines as possible?


#5

Oh god, that’s much better.
I did it the way OP did too.


#6

I figured since all the previous tasks were around arrays that was a good place to start, I had it doing what was recommended but over about 15 lines and console.log after each one.