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

iOS

Code Challenge: Arrays - Confused!

Declare an array of type 'char' called "letters" with a size of 2. Assign the variable "alpha" as the first element of the array "letters".

This is what I did

char letters[] = {alpha, };

Keeps saying "Make sure you're creating a 'char' array and giving it the correct size. As a reminder, arrays are 'zero-based' and start with 0."

I also tried

char letters[2]; letters[0] = alpha;

But no success, any ideas? :/ (thanks in advance)

Jack

5 Answers

Declare an array of type 'char' called "letters" with a size of 2

char letters[2];

Assign the variable "alpha" as the first element of the array "letters".

letters[0] = alpha;

edited my answer. Looks like what you had should have worked. are you sure you had

char letters[2];

letters[0] = alpha;

Did you make sure to keep the code from the first part of the challenge in the code section? Otherwise it will not know what "alpha" is.

I think it would have said that the previous task was no longer passing if that was the case correct?

Just tested it.

It actually does not warn the user that they deleted the previous code, it returns the exact error Jack mentioned

Ye i kept the code, this is what I have now but it says its wrong

'''char letters[2]; letters[0] = alpha;

char bravo; bravo = 'b'; '''

So am I right or whats up?

Your code for part 2 should look: char alpha = 'a'; char bravo = 'b';

char letters[2];
letters[0] = alpha;

you should have

char alpha = 'a';

char bravo = 'b';

char letters[2];

letters[0] = alpha;

letters[1] = bravo;

Thank you very much for the help both of you :)

This helped me a lot too. Initially, I deleted the declarations from the previous question. After struggling a bit I found your posts and all is good. Thanks!