Javascript 返回一个不太小也不太大的数字以用于操作?

Javascript 返回一个不太小也不太大的数字以用于操作?,javascript,function,if-statement,math,conditional-statements,Javascript,Function,If Statement,Math,Conditional Statements,我需要帮助为一个函数编写一些javascript逻辑,该函数接受一个参数,num,然后声明函数中的变量: const N = 21; const otherN = ( some logic ); const sum = ( N * otherN ) - num = some number greater than 21. 我想写一个逻辑,为常量otherN提供一些数字,我可以用num运行操作sum,这样当N*otherN从num中减去N时,总和不会小于N,而是更接近N 所需的输出将是: nu

我需要帮助为一个函数编写一些javascript逻辑,该函数接受一个参数,
num
,然后声明函数中的变量:

const N = 21; 
const otherN = ( some logic );
const sum = ( N * otherN ) - num = some number greater than 21.
我想写一个逻辑,为常量otherN提供一些数字,我可以用
num
运行操作
sum
,这样当
N*otherN
num
中减去
N时,总和不会小于
N
,而是更接近
N

所需的输出将是:

num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 10

const sum = ( N * otherN ) - num = 48; // sum equals 48
num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 124

const sum = ( N * otherN ) - num = 48; // sum equals -2688
不期望的输出将是:

num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 10

const sum = ( N * otherN ) - num = 48; // sum equals 48
num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 124

const sum = ( N * otherN ) - num = 48; // sum equals -2688
希望这是有道理的。我想,
otherN
也必须不大于num,因此有一个条件是
,但是otherN不能太大,比如
num
是200,
otherN
不能是199。这有帮助吗

var num=parseInt(Math.random()*100+1);
var N=parseInt(Math.random()*100+1);
var otherN=parseInt((N+1+num)/N)+1;
变量总和=(N*otherN)-num;

log(“num:+num+”\nN:+N+“\N另一个:+otherN+”\nsum:+sum”)为了帮助您,请以更好的方式描述变量。例如:我们有4个数字
a、b、c和d
其中
d=(b*c)-a
具有以下条件:
a>0,0