首页 > 解决方案 > If statement to confirm the numbers are a multiple of 3 and print them

问题描述

Use a for loop to go through all numbers from number up to 50 (both inclusive), and check if they are multiples of 3. If they are, print them.

for(var number = 42; number <= 50; number++)


   while (number % 3 == 0 ){
       console.log(number);
       break;
   } 

I don't know what my if statement should be.

标签: javascript

解决方案


for(var number = 0; number <= 50; number++)
    if (number % 3 == 0 ){
       console.log(number);
   }

while 循环不是您正在寻找的方式。使用 if 语句并删除break以继续迭代 for 循环


推荐阅读