Dear reader,
can you please help me understand how does the code below give a result of 15? Thank you!!
function doSomething(a){
function doSomethingElse(a) {
return a-1;
}
var b;
b = a + doSomethingElse(a*2);
console.log(b*3)
}
doSomething(2);
Dear reader,
can you please help me understand how does the code below give a result of 15? Thank you!!
function doSomething(a){
function doSomethingElse(a) {
return a-1;
}
var b;
b = a + doSomethingElse(a*2);
console.log(b*3)
}
doSomething(2);
When i try to run your code it doesn’t work
But, if you want to see what happens I would reccoment the following link: http://pythontutor.com/visualize.html#mode=display
Ahhh sorry!! I forgot to add the last element: doSomething(2)
2 + ((2*2)-1) = 5
. This is b
5*3 = 15
. This is what you print.
got it, thank you so much
I’m glad I could help. Happy coding!