var sleepCheck = function(numHours); {
if (numHours >= 8) {
return("You're getting plenty of sleep! Maybe even too much!");
};
else (numHours => 8) {
return("Get some more shut eye!");
}
sleepCheck(10);
告诉我:
然后用不同的睡眠时间调用该函数
PS:我是一个完整的业余编码,我刚刚在两天前开始使用Javascript。
答案 0 :(得分:3)
将else (numHours => 8)
更改为else
。
你也缺少一些牙箍。
var sleepCheck = function(numHours) {
if (numHours >= 8) {
return("You're getting plenty of sleep! Maybe even too much!");
} else (numHours => 8) {
return("Get some more shut eye!");
}
};
sleepCheck(10);
sleepCheck(8);
sleepCheck(5);
注意我是如何通过将闭括号与具有相应左括号的语句放在同一列上来匹配我的大括号。
如果你考虑一下,无论如何这都更有意义。 else
对条件不会有意义。这一切都很好。其条件是其前未被if
和else if
块捕获的所有其他内容。
答案 1 :(得分:0)
var sleepCheck= function(numHours){
var sleepCheck = prompt("How much did you sleep");
if(numHours>=8){
return"You're getting plenty of sleep! Maybe even too much!";
}
else (numHours<= 8);{
return "Get some more shut eye!";
}
};
sleepCheck(10);
&#13;