Reverse a String - Code not perfect

Reverse a String - Code not perfect
0

#1

Tell us what’s happening:
Hey, please let me know how to write this more eloquently and foremost, pass the challenge.

Your code so far


function reverseString(str) {
let arr=[];
for (let i=0; i>str.length; i++) {
arr.unshift(str.i);
}
let reversed = arr.toString();
reversed.replace(/[\s,]+/g,'').trim();
return reversed;
}

reverseString("hello");





Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string


#2

I suggest putting a console.log statement like below on the line before your return statement. This will allow you to look at the browser’s console (Ctrl+Shft+J in Chrome) and see exactly what you are returning. Then, you will have a better idea of how to correct your code.

console.log(reversed);

HINT: To start with, your for loop never executes any code inside, because your for loop condition is false from the beginning. Also, str.i will be undefined, because there is no property named “i” in an array. You might want to review previous lessons on how to access values from arrays before continuing with this challenge.


#3

Unfortunately I only get “undefined”, and I don’t know what to make of that…


#4

See my edited reply above for a HINT.