Adding up Array's

Hey, I have these instructions:

Create a function called addThemUp that takes in an array of numbers and returns the total of all of the items in the array added together.

Here’s my code, any help is appreciated!

var addThemUp[1,2,3,4,5];

addThemUp.reduce(function(a,b){
  return a+b;
};

Not sure I understand what it is you mean…

You need to fix that first line :

var addThemUp[1,2,3,4,5];

to

var addThemUp = [1,2,3,4,5];

Thanks that makes a lot of sense! I need the function to be addThemUp so I switched them, however I’m getting this error now:

Function returned 
15
instead of 
6
when passed 
[1,2,3]

Can you show us your current code ?

function addThemUp() { 
	var runMe = [1,2,3,4,5];

	return runMe.reduce(function(a,b){
  	return a+b;
	}); 
} 

console.log(addThemUp());

This code looks good to me, you are getting 15 as a result. and if you change addThemUp to

var addThemUp = [1,2,3];

you’ll get 6. Was this the needed result ?

Unfortunately not, I tried that and it just reverses the error :confused:

Function returned 
6
instead of 
15
when passed 
[1,2,3,4,5]

Okay, this is my code now:

function addThemUp() { 
	var runMe = [1,2,3,4,5];

	function addThemUp(runMe) {
  	return runMe;
	}; 
} 

console.log(addThemUp());

I’m being told it returns as Undefined

Sorry, I was playing around with the coding and must’ve changed it, however I do see what the issue was now.

Cannot read property 'reduce' of undefined

You function argument needs to be an array in order for .reduce to work. You need to pass this argument in the function call :

addThemUp([1,2,3]);

That last edit was it! Thank you so much for taking the time =)