freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.english.md
Oliver Eyton-Williams f1c9b08cf3 fix(curriculum): add isHidden: false to challenges
This includes certificates (where it does nothing), but does not
include any translations.
2020-05-25 16:25:19 +05:30

1.8 KiB

id, title, challengeType, isHidden, forumTopicId
id title challengeType isHidden forumTopicId
587d7b85367417b2b2512b39 Catch Missing Open and Closing Parenthesis After a Function Call 1 false 301185

Description

When a function or method doesn't take any arguments, you may forget to include the (empty) opening and closing parentheses when calling it. Often times the result of a function call is saved in a variable for other use in your code. This error can be detected by logging variable values (or their types) to the console and seeing that one is set to a function reference, instead of the expected value the function returns. The variables in the following example are different:
function myFunction() {
  return "You rock!";
}
let varOne = myFunction; // set to equal a function
let varTwo = myFunction(); // set to equal the string "You rock!"

Instructions

Fix the code so the variable result is set to the value returned from calling the function getNine.

Tests

tests:
  - text: Your code should fix the variable <code>result</code> so it is set to the number that the function <code>getNine</code> returns.
    testString: assert(result == 9);
  - text: Your code should call the <code>getNine</code> function.
    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);