在 javaScript 中使用比较表达式丢失

lost with comparison expression in javaScript

提问人:Noobtotal 提问时间:6/7/2023 最后编辑:AlanNoobtotal 更新时间:6/7/2023 访问量:39

问:

我正在做一个挑战,我已经得到了解决这个问题,但我找不到错误。

声明一个名为 speed 的变量,并将其设置为等于 90。

然后声明一个名为 busExplodes 的第二个变量,并为其赋值 检查速度是否小于 80.

将结果打印到控制台。

var speed = 90;
var busExplodes = 80 < 90;
console.log (busExplodes);

我收到此错误:>>>>Code is incorrect Your condition should evaluate if speed is lesser than 80.

我做错了什么?

JavaScript 比较

评论

0赞 Unmitigated 6/7/2023
var busExplodes = speed < 80;
0赞 Alan 6/7/2023
添加到@Unmitigated的评论中。您的代码没有实现将变量与 80 进行比较的指令。相反,您正在比较 80 到 90。speed
0赞 Noobtotal 6/7/2023
艾伦非常感谢你,很简单,哈哈哈!!

答:

0赞 JIAN SHI 6/7/2023 #1

您可以使用以下 JavaScript 代码完成此任务:

// Declare a variable named speed and set its value to 90
let speed = 90;

// Declare a second variable named busExplodes and assign it the result of a comparison expression that checks if speed is less than 80
let busExplodes = speed < 80;

// Print the result to the console
console.log(busExplodes);