Reverse a String basic algorithm

function reverseString(str) {
 let newString = "";
for (i = str.length -1; i >= 0; i--) {
newString += str[i];
}

return newString;
}

reverseString("hello");

The above code returned the expected result on the console, but failed to run here. Please help me figure out my issue. The error returned is that i is not defined. Kindly find the screenshot. Thanks.

You need to declare i with the let or var keyword.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.