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 trialParwaiz Yahya
803 PointsI believe my solution is correct for inserting the string into array for this section. It will not validate
When I copy and paste this into the playground I get the correct result. I have tried putting it in other positions in the array to see if that was the issue. I am supposed to put this second int he array. What am I doing wrong?
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")
let item = todo[2]
todo.removeAtIndex(1)
todo.insert("Learn iOS", atIndex: 1)
5 Answers
Stone Preston
42,016 Pointstask 2 states: Please remove the third item ("Deploy App") and assign it to a constant named item.
according to the removeAtIndex documentation:
removeAtIndex(_:)
Removes the element at the given index and returns it.
you need to assign the return value of calling removeAtIndex to item. you did them separately. you need to to it in one step:
let item = todo.removeAtIndex(2)
this mistake in task 2 is causing task 3 not to pass. once you fix that your code should work:
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")
let item = todo.removeAtIndex(2)
todo.insert("Learn iOS", atIndex: 1)
Parwaiz Yahya
803 PointsThank you very much!
Stone Preston
42,016 Pointsno problem
Parwaiz Yahya
803 PointsSo using your code I still get the same error: "Bummer! Your 'todo' variable has the wrong value in it."
Stone Preston
42,016 PointsI just tried my code starting from task 1 and it worked fine.
you might need to restart the challenge then and write the code for each task once more. its possible your todo variable is incorrect because of the way you did task 2. I just tried my code for task 3 and it worked fine.
task 1 should look like this:
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")
task 2:
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")
let item = todo.removeAtIndex(2)
and task 3:
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")
let item = todo.removeAtIndex(2)
todo.insert("Learn iOS", atIndex: 1)
Parwaiz Yahya
803 PointsThat did it. Must have been cashing my mistaken step 2. Thanks again.