Tell us what’s happening:
Hi!
I know my solution is quite longer than the suggested ones in the hints provided, but it’s what I came up with and I feel like it should nonetheless pass the tests, and it doesn’t, I’m a bit confused. When I try to see my results with console.log it is what is expected (‘olleh’ for ‘hello’, for example). In the meantime, I will probably try to solve it some other way, but can you help me see why it’s not passing the tests?
Thanks in advance
**Your code so far**
function reverseString(str) {
let newStr = " ";
let newArr = [];
for (let i=0; i<str.length; i++) {
newArr.unshift(str[i]);
}
for (let j=0; j<newArr.length; j++) {
if (newArr[j] !== undefined) {
newStr = newStr + newArr[j];
}
}
return newStr;
}
reverseString("hello");
Challenge: Reverse a String
Link to the challenge: