5 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
它不起作用的主要原因是因?yàn)槟阌幸粋€(gè)額外的; 在第一個(gè)條件之后。您可以將函數(shù)體縮短為一行
function isShortsWeather(temperature) { return temperature >= 75; }

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
我建議在兩個(gè) if 語(yǔ)句上返回,而不是在 false 上返回控制臺(tái)日志。您將使用 console.log 來(lái)調(diào)用該函數(shù)。我對(duì)代碼進(jìn)行了一些編輯,因?yàn)椴恍枰?2 行的分號(hào)。
function isShortsWeather(temperature) {
if (temperature < 75) {
return false;
} else {
return true;
}
}
temperature = 74;
console.log(isShortsWeather(temperature));

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
你忘了;在第 2 行,如果你刪除它它就會(huì)工作。如果你在中進(jìn)行第二個(gè) if 語(yǔ)句也會(huì)更好else if
function isShortsWeather(temperature) {
if (temperature < 75) {
return false;
} else if (temperature >= 75) {
return true;
}

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
您將在下面找到有效的正確代碼。希望回答你的問(wèn)題。
function isShortsWeather(temperature) {
if (temperature >= 75) {
return true;
}
else {
return false;
}
}
console.log(isShortsWeather(76));
console.log(isShortsWeather(74));
添加回答
舉報(bào)