gpt4 book ai didi

Javascript简单数学我不明白(初学者)

转载 作者:行者123 更新时间:2023-12-03 04:01:52 26 4
gpt4 key购买 nike

我的任务是:写下数字1-100。如果该数字可以被 3 整除,则将其写入数字“它可以被 3 整除”旁边的控制台。如果数字是 5,也将其写入数字旁边的控制台“它可以被 5 整除”,如果它不能被 3 整除,也可以被 5 保留,什么都不写

for (var listing=1;listing<=30;listing++){
if (listing % 3 != 0) {
console.log(" A(z) " + listing + " ");
} else if (listing % 5 == 0) {
console.log(" A(z) " + listing + " it can be divided with 3 and 5 ");
} else if (listing % 3 == 0){
console.log(" A(z) " + listing + " it can be divided with 3 ");
}
}

如果这个数能被两者整除就可以了。但我不知道如果数字可以被五整除的话,要写“它可以被5整除”的命令。因为这是最后不能展示的东西,请帮忙

最佳答案

我不完全确定你想要什么。这对您有帮助吗?

for (var listing = 1; listing <= 100; listing++) {
if (listing % 3 != 0 && listing % 5 != 0) {
console.log(" A(z) " + listing + " ");

} else if (listing % 3 == 0 && listing % 5 == 0) {
console.log(" A(z) " + listing + " it can be divided with 3 and 5 ");

} else if (listing % 3 == 0) {
console.log(" A(z) " + listing + " it can be divided with 3 ");

} else if (listing % 5 == 0) {
console.log(" A(z) " + listing + " it can be divided with 5 ");

}

}

关于Javascript简单数学我不明白(初学者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688863/

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