[英]Codecademy is giving me a hard time, what am I doing wrong?
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);
It is telling me to: 它告诉我:
Then call the function with different hours of sleep 然后用不同的睡眠时间调用该函数
PS: I am a complete coding amateur, I just started Javascript two days ago. PS:我是一个完整的编码爱好者,我刚刚开始使用Javascript两天前。
Change else (numHours => 8)
to just else
. 将else (numHours => 8)
更改为else
。
You're also missing some braces. 你也错过了一些牙套。
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);
Notice how I matched my braces by having the closing brace at the same column as the statement with its corresponding opening brace. 请注意我是如何通过使闭合括号与具有相应左括号的语句在同一列上来匹配我的大括号。
If you think about it, this makes more sense anyway. 如果你考虑一下,无论如何这都更有意义。 else
wouldn't make sense with a condition. else
对某个条件没有意义。 It's a catch all. 这是一个很好的结果。 Its condition is everything else not caught by the if
and else if
blocks before it. 它的条件是其他所有未被if
和else if
块捕获的条件。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.