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

C# C# Objects Encapsulation and Arrays Arrays

Ques: Set lap3 to the value in the third item of the finalLapTimes array.

I have typed this as my answer: double[] lapTimes = new double[4]; lapTimes[0] = 2.2;

double[] finalLapTimes = new double[4] {2.2, 2.3, 2.5, 2.8}; double lap3 = 2.4; finalLapTimes[2] = lap3;

Not sure what I'm doing wrong. Can someone help please...

CodeChallenge.cs
double[] lapTimes = new double[4];
lapTimes[0] = 2.2;

double[] finalLapTimes = new double[4] {2.2, 2.3, 2.5, 2.8};
double lap3 = 2.4;
finalLapTimes[2] = lap3;

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The problem here is that you have the instructions a little backwards. They want the third element assigned to lap3. you've made lap3 and put it in the third element. Take a look:

double lap3 = finalLapTimes[2];

Here we declare a new double (you could also use var) and put the 3rd element in the new variable. Hope this helps! :sparkles:

Vitaliy Raboshcuk
Vitaliy Raboshcuk
1,140 Points

double[] lapTimes = new double[4]; lapTimes[0] = 2.2; double [] finalLapTimes = new double {2.2, 2.3, 2.5, 2.8};

var lap3 =null; finalLapTimes[2] = lap3;

Bummer! Did you index into the third item of the 'finalLapTimes' array? what is wrong?

Michael Ford
Michael Ford
Courses Plus Student 1,139 Points

You assigned a null to the variable lap3. You want to assign the value in the third position of the finalLapTimes array.

Answer: var lap3 = finalLapTimes[2];

Goodluck!