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
Ian Rushton
15,789 Points"It looks like Task 1 is no longer passing" on simple array challenge.
Task 1 required me to create a new array called arrayOfInts containing 6 numbers.
arrayOfInts = [1,2,3,4,5,6]
Task 2 -
Now that we have an array declared, since it is a mutable array, we can add and remove items. Let's start by adding two more values to our existing array. There are two ways we can add items to an array and I want you to give both a try. Add one item to the array using the append method.
Remember: We invoke methods on an array using a period or dot. After the dot we write out the method name and a value to append in parentheses following the name.
Add another item to the array by concatenating an array. When concatenating, assign the results of the expression back to arrayOfInts.
This is my complete code.
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
var secondArray = [8,9,10]
arrayOfInts = arrayOfInts + secondArray
// This is returning an error saying "Task 1 no longer passes" but I cannot see why. Is there an error in my code or is there an error with the challenge itself? This was supposed to be a simple recap, oh deary me :(
5 Answers
Malerie Anderson
4,941 PointsI think it says "Task 1 is no longer passing" because you used a second array. I used the += method to append a number to the array. And it only seems to want one number appended at a time, it didn't work when I tried to append multiple numbers.
var arrayOfInts = [8, 4, 5, 2, 6, 9]
arrayOfInts.append(1)
arrayOfInts += [3]
Hope this helps!
Cariad Marketing
6,879 PointsHere's your answer. I tried the above code by Malerie but had no luck. Hope this helps anyone else that was struggling!
var arrayOfInts = [23,45,21,17,19,99]
arrayOfInts.append(55)
arrayOfInts += [67]
Ryan Rassoli
3,365 PointsWhy did you use parenthesis for the append line then use brackets while concatenating?
Uchechukwu Ejere
Courses Plus Student 5,318 PointsVar arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append ( 44 ) arrayOfInts += [ 7 ] Let value = arrayOfInts [ 4 ] Let discardedValue = arrayOfInts . removeAtIndex
stephenallison
8,559 PointsVery accurate answers
Ian Rushton
15,789 PointsIt certainly does! Thank you :)
Kellington Chidza
866 PointsarrayOfInts.append(55) arrayOfInts += [67]