gpt4 book ai didi

javascript - Javascript 中的 FizzBu​​zz 程序(已给出详细信息)

转载 作者:数据小太阳 更新时间:2023-10-29 03:58:05 24 4
gpt4 key购买 nike

<分区>

有人可以为 FizzBu​​zz 更正我的这段代码吗?似乎有一个小错误。下面的代码打印所有数字,而不是仅打印不能被 3 或 5 整除的数字。

Write a program that prints the numbers from 1 to 100. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five, print "Buzz". For numbers which are multiples of both three and five, print "FizzBuzz".

function isDivisible(numa, num) {
if (numa % num == 0) {
return true;
} else {
return false;
}
};

function by3(num) {
if (isDivisible(num, 3)) {
console.log("Fizz");
} else {
return false;
}
};

function by5(num) {
if (isDivisible(num, 5)) {
console.log("Buzz");
} else {
return false;
}
};

for (var a=1; a<=100; a++) {
if (by3(a)) {
by3(a);
if (by5(a)) {
by5(a);
console.log("\n");
} else {
console.log("\n");
}
} else if (by5(a)) {
by5(a);
console.log("\n");
} else {
console.log(a+"\n")
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com