javascript - 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.
解决方案
for(var number = 0; number <= 50; number++)
if (number % 3 == 0 ){
console.log(number);
}
while 循环不是您正在寻找的方式。使用 if 语句并删除break
以继续迭代 for 循环
推荐阅读
- javascript - jQuery 进入 Wordpress 函数.php
- android - iBeaconResult 不返回信标对象数组
- html - 我的图片和段落位置不正确
- python - hr.employee 上 odoo 上的员工人数
- google-analytics - 跨域跟踪:跟踪用户是否真正跨域
- cucumber - 空手道 + Cucumber 报告缺少被调用场景响应的文档字符串
- google-apps-script - 如何选择段落中所有带下划线的文本
- c# - 从 RazorProjectEngine 设置生成的 C# 代码的类名
- angular - 角度材料:弹出窗口:允许窗口移动到第二个监视器屏幕
- python - 如何限制pyglet中的FPS?(窗口 on_draw 事件)