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 trialJamie Redcay
7,573 Points"Make sure you're assigning the result of retrieving an item from the array to a constant named value"
"Make sure you're assigning the result of retrieving an item from the array to a constant named value" I got this error and am not sure what I'm doing wrong. Below is my code, please help.
var arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append(7) arrayOfInts += [8] arrayOfInts[4] = 9
"Make sure you're assigning the result of retrieving an item from the array to a constant named value"
I got this error and am not sure what I'm doing wrong.
Below is my code, please help.
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
arrayOfInts[4] = 9
5 Answers
Jennifer Nordell
Treehouse TeacherYou're so close here, and you've done soooo well! You've even understood indexes in arrays In fact, I'm just going to give you a hint from the instructions:
Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value.
Can you point to the part in your code where you have let value =
?
Good luck!
Jamie Redcay
7,573 Pointsvar arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
let firstTask = arrayOfInts[4]
arrayOfInts[4] = 9
I didn't have "let value = ?", but I'm still not sure where I'm going wrong
Jennifer Nordell
Treehouse TeacherOk, thought you'd get it with the hint! Give this a go
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
let value = arrayOfInts[4]
let discardedValue = arrayOfInts.removeAtIndex(5)
Happy coding!
Jamie Redcay
7,573 Pointslet value = arrayOfInts[4]
let discardedValue = arrayOfInts.removeAtIndex(5)
I didn't learn this bit of coding i my training.
you used "value" where I had "firstTask" and the second "let" statement before "= arrayOfInts.removeAtIndex(5)"
I need to better understand how and when to string code together and why.
Jennifer Nordell
Treehouse TeacherYes, I used <value>
. Again, here is the quote from the instructions:
"Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value."
The last line is for the last step in the challenge.
Jamie Redcay
7,573 PointsLOL, I was on step 3 of 4 in the code challenge the next step had me create the last line of code. that makes more sense now. Thanks
Jennifer Nordell
Treehouse TeacherYou're welcome