Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
catch-arguments-passed-in-the-wrong-order-when-calling-a-function.english.md
catch-missing-open-and-closing-parenthesis-after-a-function-call.english.md
catch-misspelled-variable-and-function-names.english.md
catch-mixed-usage-of-single-and-double-quotes.english.md
catch-off-by-one-errors-when-using-indexing.english.md
catch-unclosed-parentheses-brackets-braces-and-quotes.english.md
catch-use-of-assignment-operator-instead-of-equality-operator.english.md
prevent-infinite-loops-with-a-valid-terminal-condition.english.md
understanding-the-differences-between-the-freecodecamp-and-browser-console.english.md
use-caution-when-reinitializing-variables-inside-a-loop.english.md
use-the-javascript-console-to-check-the-value-of-a-variable.english.md
use-typeof-to-check-the-type-of-a-variable.english.md
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
portuguese
russian
spanish
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
guide
mock-guide
search-indexing
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.french.md
README.italian.md
README.korean.md
README.md
SECURITY.md
azure-pipelines.yml
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
libcimp_index_js.patch
package-lock.json
package.json
patch_npm_and_install.sh
sample.env
freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.english.md

77 lines
1.9 KiB
Markdown
Raw Normal View History

---
id: 587d7b85367417b2b2512b39
title: Catch Missing Open and Closing Parenthesis After a Function Call
challengeType: 1
---
## Description
<section id='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:
```js
function myFunction() {
return "You rock!";
}
let varOne = myFunction; // set to equal a function
let varTwo = myFunction(); // set to equal the string "You rock!"
```
</section>
## Instructions
<section id='instructions'>
Fix the code so the variable <code>result</code> is set to the value returned from calling the function <code>getNine</code>.
</section>
## Tests
<section id='tests'>
```yml
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, 'Your code should fix the variable <code>result</code> so it is set to the number that the function <code>getNine</code> returns.');
- text: Your code should call the <code>getNine</code> function.
testString: assert(code.match(/getNine\(\)/g).length == 2, 'Your code should call the <code>getNine</code> function.');
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function getNine() {
let x = 6;
let y = 3;
return x + y;
}
let result = getNine;
console.log(result);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function getNine() {
let x = 6;
let y = 3;
return x + y;
}
let result = getNine();
console.log(result);
```
</section>