Function error even though I'm correct

Tell us what’s happening:
Still getting an error for this problem " You should call reusableFunction once it is defined." even though im right. I even looked it up to make sure. any help?

  **Your code so far**

function reusableFunction() {
console.log("Hi World");
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15

Challenge: Write Reusable JavaScript with Functions

Link to the challenge:

I also tried to add an “;” after the function name but that was wrong too, idk what to do

You need to call the function. You have only defined the function.

1 Like

it says to call I put the function name next to parenthesis, like this: functionName(); I did that

This is only a function definition.

1 Like

how do I call it then? the lessons says nothing else

You can call or invoke this function by using its name followed by parentheses, like this: functionName();

You need to add a new line after the function definition that has only a function call.

I put this in function reusableFunction() { reusableFunction(); console.log("Hi World"); } and I got the first and third correct, but the second changed to incorrect

Unless you are trying to do recursion, where a function calls itself, the function call goes outside of the function definition…

const = function myFunction {
…function body stuff here…
}

myFunction();

1 Like

thats not working either. can you just tell me what the solution for this https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/write-reusable-javascript-with-functions exercise is?

click the arrow next to the solution on that page to expand it. I’d rather not post the solution here and spoil it for others :smiley:

I literally did this and its not working. I said that in my original post.

I would stop looking at solutions right now. Getting in the habit of looking at answer before you figure a solution out for yourself will cause big problems for your ability to write code on your own.

1 Like

I literally just did this in the exercise and it passed:

function reusableFunction() {
  console.log("Hi World");
}

reusableFunction();

Yes, the FCC solution doesn’t include the function call and it doesn’t pass, you are correct. I just tried it.

1 Like

Please post your new code. You have not posted code with a correct function call yet.

I got this function reusableFunction() { console.log('Hi World') } reusableFunction(); which wasn’t the solution that was on the site which is why I was confused

I think the solution on that page should be corrected. The function call probably got excluded during a copy/paste or something.

1 Like

Well, step two is to call the function.

The solution should include it, but even if it doesn’t the challenge makes it very clear that you need to call the function. Seems hard to miss, to be honest, unless you didn’t really read the challenge text and tests. I would suggest not looking at the solution before you have exhausted all other options.

Anyway, I updated the solution.

2 Likes

Agree. I try to look at solutions only after I solved it to see other ways of doing it or if I am really really stuck, then I use it and make sure I understand it fully before going on as I think that is the correct way to use solutions, rather than just using it to pass the challenge and learn nothing. Otherwise, just cheating yourself.

I mean that is what you would do if you actually wanted to learn something.

Honestly, I blame the educational systems. You get so hung up on passing tests that it almost doesn’t matter if you understand something or not. As long as you are able to pass the tests you are happy.

To be clear, this comment is not directed at any one person. It’s just a general gripe.

3 Likes