Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Introduction to Collections Adding Items to Arrays

Felix Andrew Sapalaran
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Felix Andrew Sapalaran
Python Development Techdegree Graduate 19,491 Points

let zipCode: Int = 07083 result: 7083 Can someone explain to me why index 0 is not appearing to result

Can someone explain to me why index 0 is not appearing when you call the constant variable? I tried adding another number 1, in this case 1 is the index 0 and it shows up when you call the variable.

3 Answers

Addison Francisco
Addison Francisco
9,561 Points

First of all, if you are trying to create an array, your declaration is incorrect. In your declaration, you are creating a variable of type Int with a value of 07083, which is not a valid Integer (whole number) value; You cannot have a leading zero in an integer. The compiler will remove it. If you are trying to create an array of the numbers that comprise a zip code, you could do it like so

let zipCode: [Int] = [0, 7, 0, 8, 3]

Second, if you are creating an array of zip codes and they require a leading zero, you can use a String type.

let zipCodes: [String] = ["07083", "07082", "07081"]

Hope this helps.

Addison Francisco
Addison Francisco
9,561 Points

What was the problem it asked you to solve? Can you link to it or copy and paste the question?