I typed text given in the bottom of this post, in app script. I am getting value for the =Deckel(200,1320) function as 620. For the second function =Dn(200,1320), I am getting a blank cell. What do I do to display value of n in the cell? Thank you.
function Deckel(x,y) {
let d;
for (let n=0; x*n+20 < 580;n++){d=x*(n+1)+20;}
if (d>y) {return "NOT VALID";} else {return d;}
}
function Dn(x,y) {
let d;
let n;
for (let n=0; x*n+20 < 580;n++){d=x*(n+1)+20;}
if (d>y) {return "NOT VALID";} else {return n;}
}
>Solution :
In your showing script, how about the following modification?
Modified script:
function Dn(x, y) {
let d;
let n;
for (n = 0; x * n + 20 < 580; n++) {
d = x * (n + 1) + 20;
}
if (d > y) {
return "NOT VALID";
}
return n;
}
- In your showing script,
n
is used in the loop by declaringlet n=0
. So, I removedlet
oflet n=0
. By this,n
is returned.