Javascript简单的数学我不懂(初学者)

时间:2017-06-22 01:54:39

标签: javascript

我的任务是:写数字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  ");
  }
}

如果数字可以除以它们两个就可以了。但我不知道写它的命令&#34;它可以除以5&#34;如果数字可以除以5。 因为这是最后一件事,无法展示请帮助

1 个答案:

答案 0 :(得分:1)

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

&#13;
&#13;
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  ");
		
	}

}
&#13;
&#13;
&#13;