嗨,我是一个完整的新手,刚开始在 Uni 中使用 javascript,需要帮助完成我关于“调用函数以传递参数并获取其返回值”的这部分作业
这些是作业的详细说明:
给它两个陈述。
- 第二个语句将消息返回到调用函数的地方
现在添加一个名为 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] 删除。
我来说两句