javascript - 谁能告诉我为什么这个循环永远运行?
问题描述
let dice = Math.floor(Math.random() * 6) + 1;
while (dice !== 6) {
console.log(You rolled a ${dice});
}
请解释一下这段代码?
解决方案
您只需要在循环中分配dice
值,直到while
dice !== 6
let dice = Math.floor(Math.random() * 6) + 1;
while (dice !== 6) {
console.log(`You rolled a ${dice}`);
dice = Math.floor(Math.random() * 6) + 1;
}
推荐阅读
- .net-core - IdentityServer4 使用带有 .net core 3 的 sql server
- wordpress - 我需要在这个插件中为 wp_mail() 设置“Envelope-From”标头,但它不起作用
- ios - 运行此代码时,“开关”和“扩展”行出错。为什么?
- ios13 - 在 iOS 13 中跟踪多个对象
- api - 如何在 open api 3.0 中的命名参数下嵌套 JSON 有效负载
- google-apps-script - 以编程方式离线评估 Google 表格
- publish-subscribe - 限制某些白名单 IP 的订阅者连接到 google pub sub 中的 Topic
- angular - 从表单中的复选框中检索数据
- owasp - 在 ZAP 代理扫描中排除 URL 作为守护程序运行
- neo4j - NEO4J - ORDER BY 不被识别为子条款指令,而是作为纯文本