freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../debugging/catch-missing-open-and-clos...

1.8 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7b85367417b2b2512b39 Catch Missing Open and Closing Parenthesis After a Function Call 1 在函数调用后捕获缺失的打开和关闭括号

Description

当函数或方法不接受任何参数时,您可能忘记在调用它时包括(空)开括号和右括号。通常,函数调用的结果会保存在变量中,以供代码中的其他用途使用。可以通过将变量值(或其类型)记录到控制台并看到一个设置为函数引用而不是函数返回的期望值来检测此错误。以下示例中的变量不同:
function myFunction{
回归“你摇滚!”;
}
let varOne = myFunction; //设置为等于函数
let varTwo = myFunction; //设置为等于字符串“You rock

Instructions

修复代码,使变量result设置为调用函数getNine返回的值。

Tests

tests:
  - text: 您的代码应修复变量<code>result</code>以便将其设置为函数<code>getNine</code>返回的数字。
    testString: 'assert(result == 9, "Your code should fix the variable <code>result</code> so it is set to the number that the function <code>getNine</code> returns.");'
  - text: 您的代码应该调用<code>getNine</code>函数。
    testString: 'assert(code.match(/getNine\(\)/g).length == 2, "Your code should call the <code>getNine</code> function.");'

Challenge Seed

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

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

Solution

// solution required