Javascript初学者在这里,我一直对这个问题得到错误答案:
“首先,弄清楚我们现在是否有足够的切片。使用比较运算符来确定是否有足够的。将结果分配给enoughSlicesNow变量。”
//变量低于//
var cakes = 5;
var slicesPerCake = 6;
var attendees = 60;
var bakers = 3;
var cakeBakingTime = 1;
var hoursLeftUntilParty = 5;
这是我尝试的但不接受:
(cakes * slicesPerCake)>= attendees
var enoughSlicesNow = false
答案 0 :(得分:1)
看起来你需要:
array_column()
答案 1 :(得分:0)
您可以使用三元运算符
执行此操作var cakes = 5;
var slicesPerCake = 6;
var attendees = 60;
var bakers = 3;
var cakeBakingTime = 1;
var hoursLeftUntilParty = 5;
var enoughSlicesNow = (cakes * slicesPerCake) >= attendees ?true:false
alert(enoughSlicesNow)
答案 2 :(得分:0)
你想这样吗......
var cakes = 5;
var slicesPerCake = 6;
var attendees = 60;
var bakers = 3;
var cakeBakingTime = 1;
var hoursLeftUntilParty = 5;
var enoughSlicesNow = (cakes * slicesPerCake)>= attendees;
if(enoughSlicesNow ==true){
alert('Enough');
}
else
{
alert('Not enough');
}