One question that I may be overthinking here

let testPassed = true
let errors = false

if testPassed && !errors{
print(“Whoohoo! Your code works”)
}

if testPassed = true (You have passed the test) and !errors = true (errors is true and you have errors) shouldn’t the print message say “you code doesn’t work”???

let testPassed = true
let errors = false

if testPassed && !errors{
   print("Whoohoo! Your code works")
}

the above code you provide will print your Whoohoo! Your code works, did you mean to add something else?

Explanation: testPassed is true, and the complement of errors is true (since errors alone is false, and the ! operator inverts the statement). Therefore !errors == true (and that means there are no errors).

1 Like