I need to store the return value in a variable.
I want to know how to fix this code. I know that if the value of b would be 3, I would get value=2, but if the function does more than one iteration I get unidentified. I read that I should use the callback or something but I don't know how, also an explanation of why my code doesn't work and how should I fix it. (Of course this code is for demonstration purpose as if I would show you the original it might get confusing.) Thanks a lot!
var b = 70;
function myfunction() {
b--;
if (b < 3) {
return b;
} else {
myfunction();
}
}
value = myfunction();
console.log(value);