Tell us what’s happening:
Your code so far
function reverseString(str) {
for(i=str.length-1;i>=0;i--){
string = string + str.charAt(i);
}
return string;
}
reverseString("Howdy");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.33 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/reverse-a-string
Anybody here can help me?
Actually i have done this reverse challenge but, not yet have passed it, why?
You haven’t defined string
and i
variables.
I changed your code to this to get it working.
function reverseString(str) {
var string = "";
for(var i=str.length-1; i>=0; i--){
string = string + str.charAt(i);
}
return string;
}
1 Like
Thanks…
btw can we define variable outside the function also?
And if we cant’t , why so?