Reverse a String | Basic Scripting

Hi,
I am getting reference error, that aString is not found. I don’t understand the error and the reason why test is failing.

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

  return aString;
}

reverseString("hello");

problem link -

Thanks : )

Hi.

  1. the last index of the char in the string is not equal to str.length
  1. variables declared with let are “block-scoped”. They can’t be seen outside the block.
1 Like

Got!! Thank you @udaaff :star2:

1 Like

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