8/9 How Do You "Pass it a Name"?


I really don't know how to call functions and pass it a name. Any advice?


Hi @javacoder39409,

Rather than make a really long winded post on something CodeCademy, and a lot of the internet cover very well =) I will just briefly try to give an example with comments and point you in the direction of the lesson that starts with the basics and gently builds you up on functions in JavaScript.

// This is what a function looks like:
//the name of the function is 'divideByThree'
//and it takes one argument aka a parameter, and this has the label 'number'

      //function name             argument   
var  divideByThree   = function   (number)    {
     //inside the curly braces is what the function will perform when it is called
     //it take our argument we passed in, in the label number and divide by 3
     //it will then assign the value of this expression to a variable 'val'
    var val = number / 3;

    //finally it will print this result to the console so we can see

// so now we have wrote our function we call the function by name
// Here, it is called 'dividebythree'
// We tell the computer what the number input is (i.e. 6), what argument we want to pass in to the parameter number
// The computer then runs the code inside the function!

//write the name of the function and add brackets, inside those brackets add the value you want to pass in

You can review this exact example and read up on functions under the JavaScript course Unit 2: Introduction to Functions in JS.


Thanks! I just can't get the hang of this and didn't know where to look! Thanks for the advice!