freeCodeCamp Challenge Guide: Write Reusable JavaScript with Functions

freeCodeCamp Challenge Guide: Write Reusable JavaScript with Functions
0.0 0

#1

In JavaScript, we can divide up our code into reusable parts called functions.

Here’s an example of a function:


function functionName() {
  console.log("Hello World");
}

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

functionName();

Each time the function is called it will print out the message “Hello World” on the dev console. All of the code between the curly braces will be executed every time the function is called.

Here is another example:

function otherFunctionName (a, b) {
    return(a + b);
}

We can call or invoke our function like this:

otherFunctionName(1,2);

and it will run and return its return value to us.


#2

Here’s the answer…

function ReusableFunction() {
console.log(“Hi World”);
}
reusableFunction();


#3

I put that in and it returns “reusableFunction is not defined”


#4