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 trialRay Scales
613 PointsIs there something wrong with the checking software? Why is the following syntax returning an error message?
The following syntax: todo.insert("Learn iOS", atIndex: 1) is returning the following error message which reads "Your 'todo' variable has the wrong value in it." I was told to insert "Learn iOS" element in the second position.
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App", "Fix Bugs"]
todo.removeAtIndex(3)
let item = ["Deploy App"]
todo.insert("Learn iOS", atIndex: 1)
1 Answer
Stone Preston
42,016 Pointsyour code for task 2 is incorrect. task 2 states Now that we have to fix bugs in our app we cannot deploy it. Please remove the third item ("Deploy App") and assign it to a constant named item.
you have
todo.removeAtIndex(3)
let item = ["Deploy App"]
however this removes the 4th item (index 3) instead of the third item (index 2). you also assigned item an array, however its supposed to just be the item that was removed from the array (a String)
according to the documentation, swift arrays have a method called removeAtIndex:
removeAtIndex(_:)
Removes the element at the given index and returns it.
so we can remove the item and assign that item that was removed to a constant in one step:
var todo = ["Learn Swift", "Build App", "Deploy App"]
// task 1
todo.append ("Debug App")
todo.append ("Fix Bugs")
// task 2
let item = todo.removeAtIndex(2)
// task 3
todo.insert("Learn iOS", atIndex:1)
Ray Scales
613 PointsRay Scales
613 PointsThank you!