Understanding flowchart of a function

Can someone make me understand the flowchart of this code?? How is average which has been defined within main() function accessible to the new function avg()???
How can I return average by calling main() function??

function main() {

    var num1 = parseInt(readLine(),10);

    var num2 = parseInt(readLine(),10);

    var num3 = parseInt(readLine(),10);

    

    var average=(num1+num2+num3)/3;

    //assign the average value to the variable average 

        

    console.log(average);

    

}

//complete the function

function avg(){

   return average;

    

}

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 it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

When is avg called?

why is “var average” accessible outside of main() function?

It isn’t. Are you sure avg isn’t supposed to be defined the inside main function?

Sir, here is the screengrab. Can you break it down for me now?

The function avg does not have access to the variable average in its current scope.

Are you sure there isn’t more to it and that it’s hidden behind the locked challenges?