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()
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.
function reusableFunction() {
console.log("Hi World");
reusableFunction();
}
- It looks like you deleted the code that was already there.
- You are attempting to call
reusableFunction
from insidereusableFunction
. 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.