简单赋值帮助:调用函数向其传递参数并获取其返回值

伊马卡特

赋值帮助:“调用函数以传递参数并获取其返回值”

嗨,我是一个完整的新手,刚开始在 Uni 中使用 javascript,需要帮助完成我关于“调用函数以传递参数并获取其返回值”的这部分作业

这些是作业的详细说明:

  1. 声明一个带参数和返回值的函数 •在标签内,添加一个名为getInput() 的函数和一个名为(request) 的参数。

给它两个陈述。

  • 第一条语句提示用户输入任何请求并将其存储在名为 message 的变量中。

- 第二个语句将消息返回到调用函数的地方

  1. 调用函数向其传递参数并获取其返回值

现在添加一个名为 testParamsReturn() 的函数

• 声明一个名为“firstName”的变量

• 在一行中: - 调用 getInput() 函数 - 为调用提供“名字”参数(作为字符串)。- 将函数返回的值赋给 firstName。

• 声明一个名为“secondName”的变量

• 在一行中: - 调用 getInput() 函数 - 为调用提供“第二名”参数 - 将函数返回的值分配给“第二名”。

警告“测试带有参数和返回值的函数”并附加您在​​函数中声明的两个变量

<html>
<head></head>
<body>
<section>
<input type="button" value="Function with Parameters and Return Value"     onClick="testParamsReturn()">
</section>
<script>
function getInput(request){
var message = "Enter details here";
return message;
}
function testParamsReturn(){
var firstName = "Name1";
function getInput("first_name") return firstName;
var secondName = "Name2";
function getInput("second_name") return secondName;
alert ("Testing a function with parameters and a return value of" + firstName + secondName);
} 

另一部分工作正常,但此功能使我无法单击文件中的任何按钮。

科技

我在代码中描述的所有步骤,希望对您有所帮助;)

<html>
  <head></head>
  <body>
    <section> 
      <h1> on page must be H1 tag, in section must be H1-6 tag.</h1>
      <input type="button" value="Function with Parameters and Return Value" onclick="testParamsReturn()">
    </section>
  </body>
  <script>
    // Inside the tags
    
    /* Declaring a function with parameters and return value   */
    // add a function named getInput() with a parameter named (request).
    function getInput(request){
      // The first statement prompts the user for whatever the request
      // is and stores it in a variable called message.
      var message = prompt(request);
      
      // The second statement returns the message
      return message;
    }
    
    // Now add a function named testParamsReturn() that
    function testParamsReturn(){
      // •Declares a variable named "firstName"
      var firstName;
      
      // In a single line: -Calls the getInput() function -Gives the call a parameter of “first name” (as a string). -Assigns the value returned by the function to firstName.
      firstName = getInput('first name');

    
      // •Declares a variable named "secondName"
      var secondName;
      
      // •In a single line: -Calls the getInput() function -Gives the call a parameter of “second name” -Assigns the value returned for the function to "secondName".
      secondName = getInput('second name');

      // Alerts
      alert (
        // “Testing a function with parameters and a return value of ”
        "Testing a function with parameters and a return value of " + 
        // appends both the variables you have declared in the function
        firstName + 
        ' ' +
        secondName
       );
    } 
  </script>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

缓存其参数的返回值的函数

向函数返回值的赋值如何工作?

获取异步函数参数的返回值

如何在将数组作为参数传递并让函数返回值时在 bash 中调用函数?

在调用它的函数中获取函数的返回值

从Go调用Python函数并获取函数返回值

调用javascript函数并使用匿名函数获取返回值

将函数返回值传递给存储过程参数

将函数作为参数传递给模板返回值

是否可以查询Python模拟对象以获取其调用的返回值?

从Unity中的另一个脚本调用IEnumerator方法并获取其返回值

获取作为变量传递的函数的返回值

从核心转储获取被调用函数的返回值

Java调试模式:如何获取函数调用的返回值

从python调用C ++函数并获取返回值

如何使用AJAX调用PHP函数并获取返回值?

在JavaScript中获取函数返回值作为参数

如何使用参数获取函数的返回值?

从函数获取返回值

从外部向函数返回值

Typescript-类型函数,返回作为参数传递的每个函数的返回值的UNION

如何从由argparse函数调用的函数向main返回值

如何将代码块存储在变量中,并在需要时调用它并获取其返回值?

返回值作为参数传递

在Ruby中有多个返回值的函数的条件赋值?

调用非void函数而不使用其返回值。实际发生了什么?

从作为模板函数参数传递的std :: function推断返回值和参数类型?

从ajax调用请求返回值的函数

从html调用的setInterval()函数返回值