Reverse a String- Getting right output but FCC showing its wrong

Tell us what’s happening:
Getting the following response:-

reverseString("hello")

should return a string.

reverseString("hello")

should become

"olleh"

.

reverseString("Howdy")

should become

"ydwoH"

.

reverseString("Greetings from Earth")

should return

"htraE morf sgniteerG"

. // tests completed // console output htraE morf sgniteerG

Since my output is accurate, why am i still getting arror messages?

Your code so far


function reverseString(str) {
"use strict";
const x = [...str];
var y = [];
for ( var i=(str.length-1); i>=0; i--)
{
   y.push(x[i]);

}

return reverseString = y.join('');
}
console.log(reverseString("Greetings from Earth"));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:77.0) Gecko/20100101 Firefox/77.0.

Challenge: Reverse a String

Link to the challenge:

variable reverseString is not defined , just return the value you try to assign to it.

1 Like

Hello~!

Welcome to the wonderful world of variable naming.

Your problems are caused entirely by this line. There are two issues here:

  • First, reverseString is already the name of your function. You’re now trying to assign a string value to that variable, which is throwing off the tests. You’ll need to rename this variable.
  • Second, when you rename the variable you’ll run into an error that says your variable is not defined. You’ll have to declare that variable, but you need to do it in a separate line before the return statement (you cannot return a variable declaration).
1 Like

Thank you!!! Small things make a big difference. :slight_smile:

1 Like