iOS Swift Basics Swift Operators Working With Operators

Brian Andreasen
Brian Andreasen
1,431 Points

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

operators.swift
// 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.
operators.swift
// 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
MOD
Caleb Kleveter
Treehouse Moderator 37,859 Points

While 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
Brian Andreasen
1,431 Points

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