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 trialGeorge Thomas
768 Pointsi cannot append this information to an array
i am trying to append the 6 times table (from 1-10). it keeps bringing up an error how to i do this?
// Enter your code below
var result: [Int] = []
for multiplier in 1...10 {
var answer = (multiplier * 6)
print ("\(multiplier) times 6 is equal to \(multiplier * 6)")
result.append (answer)
}
4 Answers
Myron Hicks
2,875 PointsAre you certain the array your are appending to is the right name? In my challenge it shows the array defined as results but you append to result.
William Humphrey
5,543 PointsYou donβt need to create a var answer or use a print statement. The last part is VERY close. Donβt overthink the problem.
George Thomas
768 PointsSo should it be:
var results: [Int] = []
for multiplier in 1...10 { results.append("(multiplier) times 6 is equal to (multiplier * 6)")
}
I get an error of:
swift_lint.swift:11:20: error: cannot convert value of type 'String' to expected argument type 'Int' results.append("(multiplier) times 6 is equal to (multiplier * 6)") ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Myron Hicks
2,875 PointsYou're appending the string to an integer array. All that needs to be appended to the array is the multiplication of multiplier * 6.
Everton Carneiro
15,994 PointsYou just misspelled the array name, It's results instead of result. Also you don't need to create a print statement for this task, the task is only to append the values to the arrays. Also It's not wrong, but you don't need to create a variable to store the values, you can simply do like this:
for multiplier in 1...10 {
results.append(multiplier*6)
}
Keep in mind that is this challenges you have to type exactly the same name as It's required, otherwise the challenge will not accept your answers, even if your code is write.
Myron Hicks
2,875 PointsMyron Hicks
2,875 PointsThe code should compile and run, what is your expected result? An array with 10 numbers [6,12,...60]?