Asic Algorithm Scripting: Reverse a String

Tell us what’s happening:

this challenge seems easier than maybe how I could be approaching it. Do I just create an array and use the “reverseString” variable to define the given terms it wants me to use.

Your code so far


function reverseString(str) {
return str;
  
}

reverseString("hello");

Your browser information:

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

Challenge: Reverse a String

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string

Hello, baxter.

I am not sure what you are trying to clarify. The instructions are short, because the challenge is simple. Take a look at the tests, to see what is expected to pass:

reverseString("hello") should become "olleh" .

reverseString is not a variable. It is the name of a user-defined function. You must complete the function so that it performs some operations on the parameter str, and returns the correct output.

Hope this helps

I’ve tried the Challenge answer… I’ve put together my own answers… can’t seem to get this one. Can you help me solve this answer. Like I said, I had figured this question was easy however, it stumped me. thank you.

Hello @baxterbrett, to better help, is probably best if you can provide your code so far, and we can work from there :slight_smile:

Anyhow, some pseudo-coding always goes a long way: so which step would you do if you were asked to write a sentence in reverse?
Hope this helps :+1:

got ittttttt
thank you

You can reverse a string like this:

function reverseAString(str: string): string {

let reversedWord = ' ';

  for(let i = str.length - 1; i >= 0; i--){
     reversedWord += str[i]
  }
}

console.log(reverseAString('hello'));
console.log(reverseAString('FreeCodeCamp'));

Hope that can help you :slight_smile:

Another way:


function reverseAString(str) {
    return str.split('').reverse().join('');
}

console.log(reverseAString('hello'));
console.log(reverseAString('FreeCodeCamp'));

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.