function doit(m){
    return(m+2);
}
function ask(n){
    return(n+doit(n+1)+n);
}
alert(ask(2));

How do you read this code? It returns 9 but I would like to how it does as part of my JavaScript course.

Ok dude, this function do it takes an m and adds 2 to it

so if m = 2 then doit gives you 4... thats number 1

function doit(m){ return(m+2);}

number 2, ask takes a number n, lets say 3 add 3 to 1, which is 4 and puts 4 inside the first function do it ( which as I explained adds 2 to it) so far, it gives you 6
function ask(n){ return(n+doit(n+1)+n);}alert(ask(2));

function ask(n){
return(n+doit(n+1)+n);
}

Alert gives you a popup with the value of ask inserted 2 in it, meaning 2+doit(3)+2 which is 9
alert(ask(2));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.