2 回答
TA贡献1796条经验 获得超7个赞
递归呢?
function ndn(d, n, i, ac) {
if (i === 0) return ac;
var m = n % d;
if (m !== 0) n += d - m;
ac.push(n);
return ndn(d, n + d, --i, ac);
}
ndn(22, 55, 10, []);
TA贡献1816条经验 获得超4个赞
function myFunction() {
var ans = 0;
var text = "";
var num = document.getElementById("num").value;
var div = document.getElementById("div").value;
var mod = (Number(num) + Number(div)) % Number(div);
if (mod == 0)
var ans = num;
else
var ans = (Number(num) + Number(div)) - Number(mod);
var init = 0;
if (Number(ans) % Number(div) === 0) {
text = addToText(text, ans)
init = 1;
}
for (i = init; i < 10; i++) {
ans = Number(ans) + Number(div);
text = addToText(text, ans)
}
function addToText(text, ans) {
return text + "Next TS : " + ans + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
<p>
Divisible by:
<input type="number" id="div" name="text2" placeholder="0">
<p/>
<p>
Your Number:
<input type="number" id="num" name="text1" placeholder="0" onchange="myFunction()">
</p>
<p id="demo"></p>
添加回答
举报