Need help with Basic Algorithm Scripting: Reverse a String

Tell us what’s happening:
what is wrong with my code?
how is it different from the one in the solution

Basic Algorithm Scripting: Reverse a String

Your code so far

  var reverseString = function(name) {
  var revStr = ""
  for (let i = (name.length - 1); i >= 0 ; i--) {
    revStr = revStr.concat(name.charAt(i));
  }
  console.log(revStr);
}

function reverseString(str) {
  return str;
}

reverseString("hello");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

Link to the challenge:

Looks like a single minus sign for me instead of two minus signs.

Also you should be returning your answer not console logging it.

1 Like

no i have included two minus signs in the actua code; it is just how it is displayed in the above text. however, the FCC wont accept this code.

the solution to the above challenge as provided by FCC is ```
function reverseString(str) {
return str.split(’’).reverse().join(’’);
}
``

Have you tried this?

1 Like

it worked thanks. changing from console.log to return seemed to solve the problem.
thanks again sir.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums