我的任务是:写数字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除”,如果数字可以被5整除。因为这是最后一件不能展示的东西,请帮帮忙
发布于 2017-06-22 10:01:22
我不太清楚你想要什么。这对你有帮助吗?
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 ");
}
}
https://stackoverflow.com/questions/44688863
复制相似问题