Return statement

Question:

Hi, I’m trying to use the return statement to return a value but nothing shows in the console when i try?
I am currently using JS. Please find code below.

function findFactorialRecursive(number) {
  //code here
  if(number === 2){
      return 2;
  }
  console.log(number);
  return number * findFactorialRecursive(number-1);
}

Hello @AnonUserx1, welcome to the community!

Please edit your post’s code to be formatted like this:

```
Your code here
```

So that it is easier for staff and members of the community to help you with your issue!

Also see this guide on how to share your code.

1 Like

Thanks, have updated my code :slightly_smiling_face:

1 Like

console.log doesn’t log to the replit console, rather the browser’s console. I recommend opening your website in a new tab and using developer tools (usually CTRL+SHIFT+I; or right click and you should see it). Let me know if this helps!

2 Likes

Thanks for the help, the method you say works however I would like to know if it is possible to have the method ‘’‘return number * findFactorialRecursive(number-1);’‘’ work on the replit site without having the need to open developer tools.

With the code you showed me, everything works as intended. Without developer tools you won’t be able to see what console.log says, but the function should still return the value. What is not working? Are you using that returned value?

You can open the console within Replit by pressing this button:

1 Like

I can see the console.log without using developer tools. The issue i’m having is with the Return statement. It returns no value and the console looks like this. This is what shows after I have hit run

return does not output to the console. You should do console.log(fibonacciRecursive(6))

5 Likes

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