Function 如何在函数中传递参数?
试图完成if/else代码段我的练习(问题#14),但它没有说明如何将操作值传递到函数中,因此我将其添加,但未成功。下面是我尝试给变量赋值(第1行和第2行),但得到“false”重试响应` 顺便说一句,在Codecademy的问答论坛上没有得到太多帮助:( //这行和下面的代码是静态的,由Codecademy提供Function 如何在函数中传递参数?,function,if-statement,arguments,Function,If Statement,Arguments,试图完成if/else代码段我的练习(问题#14),但它没有说明如何将操作值传递到函数中,因此我将其添加,但未成功。下面是我尝试给变量赋值(第1行和第2行),但得到“false”重试响应` 顺便说一句,在Codecademy的问答论坛上没有得到太多帮助:( //这行和下面的代码是静态的,由Codecademy提供 var checkNameGender = function (yourName,gender) { //All the code below was used in exerci
var checkNameGender = function (yourName,gender) {
//All the code below was used in exercise 1.6
if (gender.length > 0 && yourName.length > 0) {
if (gender === 'male' || gender === 'female') {
return true;
} else {
return false;
}
} else {
return false;
}
};
你已经定义了你的函数。现在你需要调用它来执行它,方法如下:
checkNameGender(yourName, gender);
它将返回结果
checkNameGender(yourName, gender);