JavaScript JavaScript Basics Creating Reusable Code with Functions Review: Giving Information to Functions

ashique desai
ashique desai
3,662 Points

how to pass the value '12' to this function?

Cannot solve this quiz. Tried with answering var = 12; in the blank space. And alert(getRandom + 12); as well to pass the value of 12 and call the function but that does not work. Please let me know how to solve this quiz.

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! Let's take a look at a sample function I wrote to demonstrate how we call a function and pass in an argument.

function sayHi(name){  //our function has one parameter
  alert("Hi there, " + name + "!");  //alert that will print out a greeting plus whatever name we send in
}

sayHi("ashique");  //call the function and pass in a name of our choosing

When we call a function we only need to write out the function name and include the argument/s in the parentheses that follow. In this case, I sent in your name. But hopefully you can extrapolate the answer from this example. Good luck! :sparkles:

ashique desai
ashique desai
3,662 Points

Thanks again Jennifer, for a very descriptive answer.