reverse a string in javascript using for loop