1.5 KiB
1.5 KiB
title, localeTitle
| title | localeTitle |
|---|---|
| Use conditional logic with If statements | 对If语句使用条件逻辑 |
对If语句使用条件逻辑
问题解释:
在函数内部创建一个if语句"Yes, that was true"如果参数wasThatTrue为true则返回"Yes, that was true" "No, that was false"否则返回"No, that was false" 。
提示1
您的if语句将评估您的(condition)是true还是false并执行(如果它的计算结果为true )后面{statement}的{statement} 。
现在尝试解决问题
提示2
如果您的(condition)求值为false ,则不会执行{statement} ,函数将返回下一个return语句。
现在尝试解决问题
扰流板警报!
提前解决!
基本代码解决方案
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
if (wasThatTrue)
{
return "Yes, that was true";
}
return "No, that was false";
// Only change code above this line.
}
代码说明
该函数首先计算if条件(wasThatTrue)计算结果为true 。如果是,则ir返回花括号之间的语句。如果没有,则返回它们之外的下一个return语句。