[solved] Can I pass an arg to this funciton

[solved] Can I pass an arg to this funciton


So theres this challenge that has this function:

funciton functionName(){
   console.log ("Heller!");

And I get that, no problem. However, what if I did…

functionName("OHHH YEAAAAA");


  • would that pass the string into the function and make it print that string instead of the one in the function definition?
  • Or should I just keep doing the challenges because I’ll find out later lol?


You will find out later. You will specify a function parameter to be able to pass data into the function. You can name the parameter almost anything, but it is recommended to name it something which explains what the data is. Continuing your example above, I would recommend naming the parameter message. Once the function is called, the actual data being passed into the function’s parameters are called arguments which are really just local function variables. You can have multiple arguments. I have added a second parameter called whoSaidThat, so I could also pass in someone’s name.

function functionName(message, whoSaidThat) {
  console.log (whoSaidThat + " said: " + message);
functionName("OHHH YEAAAAA", "John"); 

When the above code runs, the following gets displayed to the console.



Oh that’s so simple! Alright. I can do that.

:laughing: :laughing: :laughing: