freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.chinese.md
ZhichengChen 2db889099d
fix(i18n): update Chinese translation of debugging (#38045)
Co-authored-by: Zhicheng Chen <chenzhicheng@dayuwuxian.com>
2020-09-07 13:39:54 +05:30

1.7 KiB
Raw Blame History

id, title, challengeType, forumTopicId, localeTitle
id title challengeType forumTopicId localeTitle
587d7b85367417b2b2512b39 Catch Missing Open and Closing Parenthesis After a Function Call 1 301185 捕捉函数调用后缺少的左括号和右括号

Description

当函数或方法不接受任何参数时,你可能忘记在调用它时加上空的左括号和右括号。通常,函数调用的结果会保存在变量中,供其他代码使用。可以通过将变量值(或其类型)打印到控制台,查看输出究竟是一个函数引用还是函数调用的返回值来检测这类错误。 下面示例中的两个变量是不同的:
function myFunction() {
  return "You rock!";
}
let varOne = myFunction; // set to equal a function
let varTwo = myFunction(); // set to equal the string "You rock!"

Instructions

修复代码,把调用函数getNine的返回值赋给变量result

Tests

tests:
  - text: 你应该修复变量<code>result</code>使其为函数<code>getNine</code>的返回值。
    testString: assert(result == 9);
  - text: 你应该调用<code>getNine</code>函数。
    testString: assert(code.match(/getNine\(\)/g).length == 2);

Challenge Seed

function getNine() {
  let x = 6;
  let y = 3;
  return x + y;
}

let result = getNine;
console.log(result);

Solution

function getNine() {
 let x = 6;
 let y = 3;
 return x + y;
}

let result = getNine();
console.log(result);