javascript - JavaScript 中的 while 循环递减,直到达到 0 并打印“Blastoff”
问题描述
锻炼:
声明一个名为 countdown 的变量并将其赋值为 10。在while循环中,每次迭代将 countdown 的值递减一次并打印出来。一旦倒计时达到 0,将“Blastoff”打印到控制台。
到目前为止我所做的:
var countdown = 10;{
while (countdown > 0 || 0=== "Blastoff!"){
console.log(countdown);
countdown = countdown - 1;
}
console.log("Blastoff!");
}
到目前为止,这是我认为应该是正确的结果:
Output
>>>>Code is incorrect
The first line in your while's block should decrement the value of the variable countdown
10
9
8
7
6
5
4
3
2
1
Blastoff!
解决方案
终于正确了:
var countdown = 10;
while (countdown > 0){
countdown--;
console.log(countdown);
}
console.log("Blastoff");
推荐阅读
- c - 复数,cs 50,为什么 printf 函数在 if 语句之外打印不同?
- python - 使用来自 API 的数据每 5 分钟更新一次 MySQL 数据库
- android - 您如何使用侦听器中的 findViewByID 从父活动中找到视图
- haskell - 新类型的 Haskell Monoid 实例问题
- acumatica - 是否可以在 Acumatica 中使用 SOAP API 导出分支列表
- this - 我并没有真正得到构造函数方法
- python - sklearn train_test_split:当我们得到:“目标是多类但平均值='二进制'......错误时,在哪里添加平均值=无?
- javascript - 我想让我的不和谐机器人状态改变
- wordpress - 如何仅在 wordpress 博客的主页上显示智能滑块
- django - 为什么它在图像源之前注入“/product/image-name/”