Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 如何在函数中传递参数?_Function_If Statement_Arguments - Fatal编程技术网

Function 如何在函数中传递参数?

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

试图完成if/else代码段我的练习(问题#14),但它没有说明如何将操作值传递到函数中,因此我将其添加,但未成功。下面是我尝试给变量赋值(第1行和第2行),但得到“false”重试响应`

顺便说一句,在Codecademy的问答论坛上没有得到太多帮助:(

//这行和下面的代码是静态的,由Codecademy提供

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);