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 trialPaul Wirth
242 PointsVariable has the wrong output to it, objective says to insert an element at the second position of my array.
So I put todo.insert("Learn iOS", atIndex: 1) and it says i have the wrong output. I don't understand what I might've messed up. Can someone point me in the right direction?
Jason Anello
Courses Plus Student 94,610 Pointsobey me,
The question links to the challenge in the "Related content" section in the right column.
5 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Paul,
The code you have for task 3 is fine. Can you post all the code that you have?
You want to make sure that you've kept all the previous code in place.
Also, you could refresh the challenge page and try again.
Jason Anello
Courses Plus Student 94,610 PointsIn task 2 you were supposed to remove the 3rd element or the element at index 2. You removed at index 1.
For task 3 you are supposed to insert "Learn iOS" at the second position. That would be index 1. You are inserting at index 0.
obey me
1,135 PointsBasically if you are inserting a new item in the array i will consider don't make the array constant because if you are inserting you are modifying which is where will get an error
var hello = ["A","B","C"]
hello.insert("D",atIndex:3)
Paul Wirth
242 PointsHere is the Question: Finally, we forgot to add that we need to learn iOS development prior to building an app. Insert a new item titled "Learn iOS" at the second position in the todo array. Here is my code:
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append ("Debug App")
todo.append ("Fix Bugs")
todo.removeAtIndex (1)
let item = todo.removeAtIndex (1)
todo.insert("Learn iOS",atIndex:1)
This is the error: Bummer! Your 'todo' variable has the wrong value in it.
obey me
1,135 Pointsvar t = ["Learn Swift", "Build App", "Deploy App"]
t.append ("Debug App")
t.append ("Fix Bugs")
t.removeAtIndex (1)
let item = t.removeAtIndex (1)
t.insert("Learn iOS",atIndex:0)
t
// I mean your code is good i just you had every code on the same line
Paul Wirth
242 PointsHaha it just copy and pasted that way. So by value im assuming that it means the location in my array correct?
obey me
1,135 Pointswhat you said
obey me
1,135 Pointsobey me
1,135 Pointswhat is the question asked ?