While and scope

When I was trying to solve the exercise came up this doubt.

Where I have to put return?
Because I try one time inside while loop and give an error, outside it’s out of scope.

The return will end your loop, so you can put it in a while only if you wanted to stop looping because an event occurred.
You can put it outside. The “out of scope” error is not related to the return itself, but to the variable you’re returning. If you declare it in the while loop, it doesn’t exist anymore once you get out from the loop. So you have to declare that variable outside, or copy it in some global variable before leaving the loop

Thank you, do you know some tutorial to learn more about structure code?

Try this:

https://www.w3schools.com/js/default.asp

it could be good for a first look. The better I can suggest is any book of programming principles (even based on js). Every different programming language has its own syntax but many of them are really similar, but most important: the basic structure (loop, interruptions and so on) has a common base with almost any language.

Thank you, I know this website.