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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

What does the function print(message) do?

In creating HTML using array, What does the function print do? Does "message" have a value?

var playList = [
  'I Did It My Way',
  'Respect',
  'Imagine',
  'Born to Run',
  'Louie Louie',
  'Maybellene'
];

function print(message) {
  document.write(message);
}

4 Answers

jason chan
jason chan
31,009 Points
// let playlist hold an array of words comma seperated
var playList = [
  'I Did It My Way',
  'Respect',
  'Imagine',
  'Born to Run',
  'Louie Louie',
  'Maybellene'
];

// we create a function print with argument. 
function print(message) {
  console.log(message);
}

// we get array start at 0 to 6 and see how to call each single array example playlist[0]
print(playList); // we call the function here with ("we pass in playList")

// your going to need for loop to print every single thing in array.

the argument (message), what does this mean?

jason chan
jason chan
31,009 Points

An argument is place holder for something you want to pass into it. For example variable or function or object.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments

below is video about functions from algebra 1

https://youtu.be/qsySYJ2MgOM

do you remember functions in algebra?

Thanks, I will watch check out the links you posted. You have been most helpful.

Hi.

The "message" is a variable argument that you send to the function.

function send(message){ // the message contains the string 'Hi' - you can then assign this variable to another variable in the function scope if you wish or just use it directly

console.log(message); // prints out 'Hi' to the console

}

send('Hello, there!'); // This way you directly send a value to the function
-----
var message = 'Hi'; // you can declare a variable to be sent into the function 
send(message); // this is same as sending 'Hi' as a direct value

Hope this helps.