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

Russell Roberts
Russell Roberts
21,482 Points

I keep getting a error message on this code challenge. I'm pretty sure that is correct. Any thought?

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", "Deploy App"] todo.append ("Debug App") todo.append ("Fix Bugs")

todo.removeAtIndex (1) let item = todo.removeAtIndex (1) todo.insert("Learn iOS", atIndex:1)

arrays.swift
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)

3 Answers

Stone Preston
Stone Preston
42,016 Points

your 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.

the third item is at index 2. you removed index 1. also you removed it twice. just remove the second index once and assign the return value to item.

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)

if you try the code above and it still does not work, restart the challenge and add the code for each task one by one.

Mikael Enarsson
Mikael Enarsson
7,056 Points

Remove the first todo.removeAtIndex

Russell Roberts
Russell Roberts
21,482 Points

Thanks for the help. That makes sense.