5 回答

TA贡献1906条经验 获得超10个赞
它不起作用的主要原因是因为你有一个额外的; 在第一个条件之后。您可以将函数体缩短为一行
function isShortsWeather(temperature) { return temperature >= 75; }

TA贡献1777条经验 获得超3个赞
我建议在两个 if 语句上返回,而不是在 false 上返回控制台日志。您将使用 console.log 来调用该函数。我对代码进行了一些编辑,因为不需要第 2 行的分号。
function isShortsWeather(temperature) {
if (temperature < 75) {
return false;
} else {
return true;
}
}
temperature = 74;
console.log(isShortsWeather(temperature));

TA贡献1802条经验 获得超10个赞
你忘了;在第 2 行,如果你删除它它就会工作。如果你在中进行第二个 if 语句也会更好else if
function isShortsWeather(temperature) {
if (temperature < 75) {
return false;
} else if (temperature >= 75) {
return true;
}

TA贡献1813条经验 获得超2个赞
您将在下面找到有效的正确代码。希望回答你的问题。
function isShortsWeather(temperature) {
if (temperature >= 75) {
return true;
}
else {
return false;
}
}
console.log(isShortsWeather(76));
console.log(isShortsWeather(74));
添加回答
举报