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

how can i make a function return the contents of an array? ex. function print(array)

i want to write a function called print that will return the variables in an array to the console. i have this so far:

function print(array, instructions) { var output = []; for (var i=0; i<array.length;i++) { output.push(instructions(array[i])); } return output; }

.....im not sure what to do.

Can you use an example to explain what exactly do you want to achieve? For example you want to convert a var array = [0,1,2,3] into what?

2 Answers

function print() {
            for (var i = 0; i < arguments.length; i++) {
                console.log(arguments[i])
            };
        }
//Example
        print("12",23,"Hola",12,44)

I think that’s it

Here is a quick fix for your code:

var arrayToConvert = ["12",23,"Hola",12,44];

function print(parameter) {
            for (var i = 0; i < parameter.length; i++) {
                console.log(parameter[i])
            };
        }

print(arrayToConvert);

@César Guadarrama Cantú
Thank you. i see from your resposne that I forgot For. Gabriel D. Celery Thank you. I noticed how you created a Variable to understand its place in the function