Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Which of the following shows an example of passing an argument to a function?

A alert("Hello world!") B document.write("<h1>Welcome</h1>") C Math.floor(2.2) D getArea(10, 20, 'sq ft') E All of the above. i think answer should be (D) but the correct answer is all the above how is it correct?? because u can pass arguments only inside function call .

2 Answers

I guess one way to look at it is:

document.write("<h1>Welcome</h1>")

is essentially:

myFunctions("Arguments this functions accepts");

So once the function is created, you can then call the function and pass in the arguments.

The answer D is the same as all of the other functions in the list, but in this case it accepts 2 values instead of 1.

how The answer D is the same as all of the other functions in the list, here in this line : document.write("<h1>Welcome</h1>") we are not passing any arguments to a function here we are simply printing "welcome". similarly all other options are simply displaying .they are not giving any kind of values to the functions for eg : function sentence(str) { return alphabets; } alert("Hello") ;

/*option (a) here alert,document.write ,document.write
nothing have to do with function sentence */

sentence('welcome') ; // option (d ) is passing argument to function

andren
andren
28,558 Points

here in this line : document.write("<h1>Welcome</h1>") we are not passing any arguments to a function here we are simply printing "welcome".

document.write is a function, and the string that is passed in "<h1>Welcome</h1>" is an argument. You seem to be confused about what constitutes a function.

Any collection of code that can be called by typing a name and adding parenthesis, like alert, document.write, console.log, Math.round and the like are examples of functions. And any value you pass to them within those parenthesis like "<h1>Welcome</h1>", "Hello World", 2.2, etc are example of arguments.

As Martin Jones said the only difference between the different answers is that answer D accepts more than one argument.

oh yes i just totally forgot that alert ,console documents they all are in built function thank you very much Martin Jones and andren for you time thank you adren for your help . my doubt is clear now.

Otec Perez Glass
Otec Perez Glass
7,678 Points

Hello even though document.write , alert, console.log and other are functions that we can pass information to it if i or some else have selected the option d (getArea (info)) should not be wrong in your system so try use like a check box that we can select different answers .