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 trialElfar Oliver
3,924 PointsThe last was 32 but then we changed the value of [2](which is the last one) to 20 and it was still 32. Any reason why?
csharp> lockCombination[2] = 20;
csharp> last
32
csharp> lockCombination
{ 10, 5, 20 }
1 Answer
Caleb Kemp
12,755 PointsSo the first thing that can be tricky is, if you have [2]
it is actually referring to the third item in the list. so for list [0, 5, 17]
, list[2]
would be 17. But, unless I'm mistaken, the part that is giving you trouble is that you have two different variables here. One named last
, with a value of 32
, and one called lockCombination
. When you wrote
csharp> lockCombination[2] = 20;
it did indeed change the value of lockCombination[2]
to 20. You can see that by looking at the value of the third value of your output
csharp> lockCombination { 10, 5, 20 }
however, this did not change the value of last
, so it is still 32. If you wanted to also change the value of last
to 20, you would need to write something like last = 20;
Hope that helps.