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.