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 trialBrian Andreasen
1,431 PointsGetting an error message saying the code isn't right, works in Xcode 10
I am getting the following message when trying to submit the code for this task:
Bummer: Your code could not be compiled. Please click on "Preview" to view the compiler errors.
I tried this on my mac using Xcode 10 and this code works properly.
Keep in mind the instructions say to assign the result to isPerfectMultiple as a constant.
You can't do that as its illegal to change a constant in swift you change a var.
If a var is provided it still doesn't accept it.
// Enter your code below
let value = 200
let divisor = 5
let someOperation = 20 + 400 % 10 / 2 - 15
let anotherOperation = 52 * 27 % 200 / 2 + 5
// Task 1 - Enter your code below
let result = value % divisor
// Task 2 - Enter your code below
if (result == 0){
let isPerfectMultiple = true
}
Even when the following code is supplied I'm getting non compilation errors but only warnings in Xcode using this code snippet. No output is supplied for this task.
// Enter your code below
let value = 200
let divisor = 5
let someOperation = 20 + 400 % 10 / 2 - 15
let anotherOperation = 52 * 27 % 200 / 2 + 5
// Task 1 - Enter your code below
let result = value % divisor
// Task 2 - Enter your code below
if (result == 0){
let isPerfectMultiple = result
}
1 Answer
Caleb Kleveter
Treehouse Moderator 37,862 PointsWhile your code is technically correct (it compiles and runs), it doesn't have the values expected by the challenge.
Your only issue is with task 2, where you have the equality operator:
if (result == 0){
let isPerfectMultiple = result
}
Here, you are creating a constant called isPerfectMultiple
with the value of result
if result
, and you are only creating it if result
is equal to 0
.
What you should be doing is always creating the isPerfectMultiple
constant, and instead of assigning it the value of result
, you should assign it the boolean value of whether result
is equal to 0
or not.
Hope that makes sense!
Brian Andreasen
1,431 PointsBrian Andreasen
1,431 PointsMake sense Caleb.
I was able to take a break and come back to it and realized where I was going wrong. The challenge has been passed at this point.