Different apporach

Tell us what’s happening:
Describe your issue in detail here.
my program is working perfectly fine but it doesn’t filll up nercessry condition could anyone just explain me

  **Your code so far**

function reverseString(str) {
let word=str;
let newword="";
console.log(newword)
for(let i=word.length-1;i>-1;i--)
{
newword=word[i];
console.log(newword)
}
return newword;


}

reverseString("hello");
  **Your browser information:**

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

Challenge: Reverse a String

Link to the challenge:

Try console logging what the function actually returns.

console.log(reverseString("hello"))
2 Likes

Let’s look at what output you get:

function reverseString(str) {
  let word = str;
  let newword = "";
  console.log(newword)
  for (let i = word.length - 1; i > -1; i--) {
    newword = word[i];
    console.log(newword)
  }
  return newword;
}

console.log("final result:", reverseString("hello"));

What do you notice?

1 Like
thanks apperciate it.now i have finally resolve the issue just look at the code
function reverseString(str) {

  let word = str;

  let newword = "";

  console.log(newword)

  for (let i = word.length - 1; i > -1; i--) {

    newword += word[i];

    console.log(newword)

  }

  return newword;

}

console.log("final result:", reverseString("hello"));

thanks i apperciate it

Since your code works, I put spoiler tags around it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.