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 trial

iOS Swift Basics (retired) Collections Modifying an Array

Why is it saying my todo variable has the wrong value? What am I doing wrong?

I am on challenge 3 of 3 in the modifying arrays quiz and I am getting an error message that says: "Your todo variable has the wrong value".

var todo = ["Learn Swift", "Build App"] todo.append("Debug App") todo.append("Fix Bugs") todo[2] = "Deploy App" let item = todo.removeAtIndex (2) todo.insert("Learn iOS", atIndex: 1)

3 Answers

Stone Preston
Stone Preston
42,016 Points

you are close. you have an unnecessary line in your code.

remove the following line of code:

todo[2] = "Deploy App"

you were not asked to add it. after removing it you should have

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)

which is what you need to pass.

It worked! Thank you so much.

Russell Roberts
Russell Roberts
21,482 Points

I'm have the same problem but I don't have a unnecessary line of 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)

Stone Preston
Stone Preston
42,016 Points

you do have an unnecessary line. you need to assign the return value of removeAtIndex to the constant item in one step.

let item = todo.removeAtIndex (2)

you currently have:

todo.removeAtIndex (1)
let item = todo.removeAtIndex (1)

you are removing the index twice, you only need to do it once

using the correct line your complete code should look like this:

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)
McKenna Rowe
McKenna Rowe
2,930 Points

thanks for posting this--I think this lesson needs little bit of cleanup to the error checking