* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
3.0 KiB
3.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
cf1111c1c12feddfaeb3bdef | Use Conditional Logic with If Statements | 1 | 使用条件逻辑和If语句 |
Description
If
语句用于在代码中做出决定。关键字if
告诉JavaScript在括号中定义的特定条件下执行花括号中的代码。这些条件称为Boolean
条件,它们可能只是true
或false
。当条件计算结果为true
,程序将执行花括号内的语句。当布尔条件的计算结果为false
,大括号内的语句将不会执行。 伪代码 if( condition为true ){例
声明被执行
}
功能测试(myCondition){当使用值
if(myCondition){
回归“这是真的”;
}
返回“这是假的”;
}
测试(真); //返回“这是真的”
测试(假); //返回“这是假的”
true
调用test
, if
语句将评估myCondition
以查看它是否为true
。因为它是true
,函数返回"It was true"
。当我们使用false
值调用test
时, myCondition
不为 true
并且不执行花括号中的语句,函数返回"It was false"
。 Instructions
if
语句"Yes, that was true"
如果参数wasThatTrue
为true
则返回"Yes, that was true"
"No, that was false"
否则返回"No, that was false"
。 Tests
tests:
- text: <code>trueOrFalse</code>应该是一个函数
testString: assert(typeof trueOrFalse === "function");
- text: <code>trueOrFalse(true)</code>应该返回一个字符串
testString: assert(typeof trueOrFalse(true) === "string");
- text: <code>trueOrFalse(false)</code>应该返回一个字符串
testString: assert(typeof trueOrFalse(false) === "string");
- text: <code>trueOrFalse(true)</code>应该返回“是的,那是真的”
testString: assert(trueOrFalse(true) === "Yes, that was true");
- text: <code>trueOrFalse(false)</code>应该返回“No,that was false”
testString: assert(trueOrFalse(false) === "No, that was false");
Challenge Seed
// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
// Only change code above this line.
}
// Change this value to test
trueOrFalse(true);
Solution
// solution required