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

Java

Create an array named data and store any 3 numbers in it.

my code keeps on saying bummer int[]data={1,2,3};

7 Answers

It is looking for integers, not strings. When you add quotes around the numbers, it becomes a string. Try:

var data = [ 1, 2, 3 ];

Hopefully this helps someone in the future, I thought I was crazy.

var data = [ '1', '2', '3' ];

//Note the numbers are in strings. -Numbers do not go in strings unless your stringing it together with something else. Am I right?

Thank you so so much for this. I thought I was going insane!

var data = [1,2,3];

Yes -> var data = [1,2,3]; worked. Thanks Gabriel

Hi friends,

The formatting in Example 1 will be marked as incorrect for this challenge.

Example 1: var data = [ '1', '2', '3' ];

Be sure to format your answer to look like the bit of code highlighted in Example 2. Although the mentor used apostrophes in his array from the video just before this challenge, you will want to present your answer without them, (see Example 2 for correct formatting).

Example 2: var data = [ 1, 2, 3 ];

So what's different about Example 1 and Example 2? There are no apostrophes.

Hint: Apostrophes are the ' ' characters.

Simply omit the apostrophes from your array and the challenge should now pass...

solution:

script.js
var data = [ 3, 4, 5 ];
var assorted = [ 'string', 3, true ] ;
Nicolas Hampton
Nicolas Hampton
44,725 Points

Try using the brackets to store the numbers, like

int[] data = [1,2,3];

You might also need to declare the size of the array beforehand to put anything in it,

int[] data = new int[3];
Nicolas Hampton
Nicolas Hampton
44,725 Points

Actually, only use the brackets for declaring the size, then use the {} for the number instances.

its not working