JS: Write Reusable JavaScript with Functions

I need help with this one. I do not how to call the function.

What do you have? What have you tried?

I was looking in Google to try to figure this out. I thought from the explanations on there that you were supposed to put the word ‘call’ in the parenthesis beside the function name, but that was wrong. Then thought maybe I should copy there example function name, but I interpreted it right the first time. After that, other than simple mistakes like misspelling a word or putting the brackets in the wrong place, I haven’t tried anything else. This is my code so far:

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

I guess I’m still confused about what you are trying to accomplish. The code you have above is a function that will print “Hi World” to the console when it is called.

You call functions with parenthesis.

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

reusableFunction(); // this will log "Hi World" to the console.

.call() and .bind() are specialized functions that allow you to redefine “this” and ultimately allow you to change the context that your method is running in. If that doesn’t quite make sense, that’s okay because you shouldn’t use these unless you know what you’re doing and its absolutely necessary. - just know that all you need to call a method is ().

PS: console.log is also a function, thus is called by using console.log()

1 Like

I fixed it a little bit, but It still says this:

“reusableFunction should output “Hi World” to the dev console”

Please share the exact code that you have in the the solution box.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

function reusableFunction() {
  console.log("Hi World");
  reusableFunction();
}
  1. It looks like you deleted the code that was already there.
  2. You are attempting to call reusableFunction from inside reusableFunction. Without protection, this would cause infinite recursion and crash your browser.

Sorry, I just copied the part that I was having trouble with. I did figure it out though.
I make simple mistakes a lot and this was one of them. As it turns out, I had the outside function too far away.