samedi 6 juin 2020

Using If statements to handle multiple conditions

I am trying to write some code that calculates the phenotype of a given genotype.
I have declared the genes in the following code which has three options, for instance ee, Ee, and EE.

Certain combinations give certain colours. I am finally at the point where I can make the genes change an image at the top of the app, but I keep getting errors with my if statements. I have tried using blabla.contains, arrays, etc

These are the combinations I am trying to get in my code:

  1. chestnut: ext = ee
  2. bay: ext = Ee or EE, ago = AA or Aa
  3. black: ext = EE or Ee and ago = aa

My code:

var ext = String("ee")
var ago = String("aa")

func checkPicture() {
    if ext = "EE" || "Ee" && ago == "aa" {
        baseLayer.image = #imageLiteral(resourceName: "black")
        base = String("black")
    }
    if ago == "Aa" || "AA" && ext == "EE" || "Ee" {
        baseLayer.image = #imageLiteral(resourceName: "bay")
        base = String("bay")
        }
    if ext == "ee" {
        baseLayer.image = #imageLiteral(resourceName: "chestnut")
        base = String("chestnut")
    }
}

Aucun commentaire:

Enregistrer un commentaire