Newbie functions

How to write this code correctly so that the function result() returns the sum of the var bask1+bask2…
the error is “bask1 is undefined”

function apples(){
    var bask1 = 20;
    var bask2 = 30;
apples(); 
    
    
function pears(){
    var bask3 = 40;
    var bask4 = 50;
pears();
        
        }
}

function result(){
    
    var total = bask1+bask2+bask3+bask4;

            alert("apples & pears = " + total);
    
    }

result();

have you went through some course on JS, learning how to declare functions/variables, what scope is etc? Your code is broken, its hard to even tell what you are trying to achieve there. We can put you the right answer, which is nothing complicated, but you would learn nothing and it wont fill the gaps you have in your understanding of functions and variables.

thanks “dad”
you are very helpful

bask1 is undefined because it is scoped inside the apples function

You are also calling both functions inside themselves which you should not be doing in your code

How much experience do you have with JavaScript? Have you followed a course in basic syntax?