title: Why is my conditional statement in Swift not working?
body: <pre><code>var word1array = [colorwordw1, colorwordg1, colorwordb1]
  var word1 = word1array [ofThree()]
  </code></pre>
  
  <p><code>[ofThree()]</code> function is:</p>
  
  <pre><code>func ofThree() -&gt; Int {
      return Int(arc4random() % 3)
  }
  </code></pre>
  
  <p>For some reason, the following conditional statement always evaluates as true</p>
  
  <pre><code> @IBAction func White1Action(sender: AnyObject) {
  
      if (word1 == colorwordw1) {
  
  
          [moveTilesDown()]
  
  
          [RandomPlacementTwo()]
  
  
       }
  </code></pre>
  
  <p>What is wrong with my code?</p>
  
  <p>Thanks</p>
  
  <p>inits:</p>
  
  <pre><code>var colorwordw1 = "White"
  var word1 = "White"
  </code></pre>
  
  <p>more context</p>
  
  <pre><code>var colorwordsarray:[String] = ["Blue","Red","Green","Yellow","Gray","Cyan","Magenta","Orange","Purple","White","Brown","Black"]
  
  var colorwordw1 = colorwordsarray[random12]
  
  random12 = ofTwelve()
  
  func ofTwelve() -&gt; Int {
      return Int(arc4random() % 12)
  }
  </code></pre>
  
  <p>Here is all the code:</p>
  
  <pre><code>class ViewController: UIViewController {
  
  
  
      @IBOutlet weak var whiteTile1: UIButton!
  
      @IBOutlet weak var greyTile1: UIButton!
  
  
      @IBOutlet weak var blackTile1: UIButton!
  
      @IBOutlet weak var whiteTile2: UIButton!
  
      @IBOutlet weak var greyTile2: UIButton!
  
      @IBOutlet weak var blackTile2: UIButton!
  
      @IBOutlet weak var whiteTile3: UIButton!
  
      @IBOutlet weak var greyTile3: UIButton!
  
      @IBOutlet weak var blackTile3: UIButton!
  
      @IBOutlet weak var whiteTile4: UIButton!
  
      @IBOutlet weak var greyTile4: UIButton!
  
  
      @IBOutlet weak var blackTile4: UIButton!
  
  
      @IBOutlet weak var whiteTile5: UIButton!
  
      @IBOutlet weak var greyTile5: UIButton!
  
      @IBOutlet weak var blackTile5: UIButton!
      @IBOutlet weak var colorText5: UILabel!
      @IBOutlet weak var colorText4: UILabel!
      @IBOutlet weak var colorText3: UILabel!
      @IBOutlet weak var colorText2: UILabel!
      @IBOutlet weak var colorText1: UILabel!
  
  
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  
  
  
  // function returns 1-3 randomly
  
      func ofThree() -&gt; Int {
          return Int(arc4random() % 3)
      }
  
  // variable array for color, with three options - used with above function to later define word variable
  
      var wordarray:[String] = ["White", "Grey", "Black"]
  
  //     var ofThree = Int(arc4random() % 3)
  
      func ofTwelve() -&gt; Int {
          return Int(arc4random() % 12)
      }
  
      var colorarray = [UIColor.blueColor(),UIColor.redColor(),UIColor.greenColor(),UIColor.yellowColor(),UIColor.grayColor(),UIColor.cyanColor(),UIColor.magentaColor(),UIColor.orangeColor(),UIColor.purpleColor(),UIColor.whiteColor(),UIColor.brownColor(),UIColor.blackColor()]
  
      var colorwordsarray:[String] = ["Blue","Red","Green","Yellow","Gray","Cyan","Magenta","Orange","Purple","White","Brown","Black"]
  
      // init word variable
  
      var word = "White"
      var word1 = "White"
      var word2 = "White"
      var word3 = "White"
      var word4 = "White"
      var word5 = "White"
      var colorw1 = UIColor.whiteColor()
      var colorw2 = UIColor.whiteColor()
      var colorw3 = UIColor.whiteColor()
      var colorw4 = UIColor.whiteColor()
      var colorw5 = UIColor.whiteColor()
      var colorg1 = UIColor.whiteColor()
      var colorg2 = UIColor.whiteColor()
      var colorg3 = UIColor.whiteColor()
      var colorg4 = UIColor.whiteColor()
      var colorg5 = UIColor.whiteColor()
      var colorb1 = UIColor.whiteColor()
      var colorb2 = UIColor.whiteColor()
      var colorb3 = UIColor.whiteColor()
      var colorb4 = UIColor.whiteColor()
      var colorb5 = UIColor.whiteColor()
      var colorwordw1 = "White"
      var colorwordw2 = "White"
      var colorwordw3 = "White"
      var colorwordw4 = "White"
      var colorwordw5 = "White"
      var colorwordg1 = "White"
      var colorwordg2 = "White"
      var colorwordg3 = "White"
      var colorwordg4 = "White"
      var colorwordg5 = "White"
      var colorwordb1 = "White"
      var colorwordb2 = "White"
      var colorwordb3 = "White"
      var colorwordb4 = "White"
      var colorwordb5 = "White"
  
      var random12 = 12
  
  
   func moveTilesDown(){
  
      colorText5.center.y += 142
      colorText4.center.y += 142
      colorText3.center.y += 142
      colorText2.center.y += 142
      colorText1.center.y += 142
      whiteTile1.center.y += 142
      whiteTile2.center.y += 142
      whiteTile3.center.y += 142
      whiteTile4.center.y += 142
      whiteTile5.center.y += 142
      greyTile1.center.y += 142
      greyTile2.center.y += 142
      greyTile3.center.y += 142
      greyTile4.center.y += 142
      greyTile5.center.y += 142
      blackTile1.center.y += 142
      blackTile2.center.y += 142
      blackTile3.center.y += 142
      blackTile4.center.y += 142
      blackTile5.center.y += 142
      [self.view .bringSubviewToFront(colorText1)]
      [self.view .bringSubviewToFront(colorText2)]
      [self.view .bringSubviewToFront(colorText3)]
      [self.view .bringSubviewToFront(colorText4)]
      [self.view .bringSubviewToFront(colorText5)]
  
      // get new random word and update label
  
  
  
  
  
  
  
  
       // if title row is too low, move row to the top
  
      if (whiteTile1.center.y &gt;= 601) {
          whiteTile1.center.y = -71
          greyTile1.center.y = -71
          blackTile1.center.y = -71
          colorText1.center.y = -142
          random12 = ofTwelve()
          var colorw1 = colorarray[random12]
          var colorwordw1 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorg1 = colorarray[random12]
          var colorwordg1 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorb1 = colorarray[random12]
          var colorwordb1 = colorwordsarray[random12]
          var word1array = [colorwordw1, colorwordg1, colorwordb1]
          var word1 = word1array [ofThree()]
          whiteTile1.backgroundColor = colorw1
          greyTile1.backgroundColor = colorg1
          blackTile1.backgroundColor = colorb1
          [self.view .bringSubviewToFront(colorText1)]
          colorText1.text = word1
          colorText1.hidden = false
  
  
  
      }
  
  //    if colorw1 == colorg1 {
  //        
  //        random12 = ofTwelve()
  //        var colorw1 = colorarray[random12]
  //        var colorwordw1 = colorwordsarray[random12]
  //        var word1array = [colorwordw1, colorwordg1, colorwordb1]
  //        word1 = word1array [ofThree()]
  //        whiteTile1.backgroundColor = colorw1
  //    }
  //        
  //    } else {
  //        
  //        if colorw1 == colorb1 {
  //
  //        random12 = ofTwelve()
  //        var colorw1 = colorarray[random12]
  //        var colorwordw1 = colorwordsarray[random12]
  //        var word1array = [colorwordw1, colorwordg1, colorwordb1]
  //        word1 = word1array [ofThree()]
  //        whiteTile1.backgroundColor = colorw1
  //        
  //        }
  //        
  //    }
      if (whiteTile2.center.y &gt;= 600) {
          whiteTile2.center.y = -71
          greyTile2.center.y = -71
          blackTile2.center.y = -71
          colorText2.center.y = -142
          random12 = ofTwelve()
          var colorw2 = colorarray[random12]
          var colorwordw2 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorg2 = colorarray[random12]
          var colorwordg2 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorb2 = colorarray[random12]
          var colorwordb2 = colorwordsarray[random12]
          var word2array = [colorwordw2, colorwordg2, colorwordb2]
          var word2 = word2array [ofThree()]
          whiteTile2.backgroundColor = colorw2
          greyTile2.backgroundColor = colorg2
          blackTile2.backgroundColor = colorb2
          [self.view .bringSubviewToFront(colorText2)]
          colorText2.text = word2
          colorText2.hidden = false
  
  
      }
      if (whiteTile3.center.y &gt;= 600) {
          whiteTile3.center.y = -71
          greyTile3.center.y = -71
          blackTile3.center.y = -71
          colorText3.center.y = -142
          random12 = ofTwelve()
          var colorw3 = colorarray[random12]
          var colorwordw3 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorg3 = colorarray[random12]
          var colorwordg3 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorb3 = colorarray[random12]
          var colorwordb3 = colorwordsarray[random12]
          var word3array = [colorwordw3, colorwordg3, colorwordb3]
          var word3 = word3array [ofThree()]
          whiteTile3.backgroundColor = colorw3
          greyTile3.backgroundColor = colorg3
          blackTile3.backgroundColor = colorb3
          [self.view .bringSubviewToFront(colorText3)]
          colorText3.text = word3
          colorText3.hidden = false
  
  
      }
      if (whiteTile4.center.y &gt;= 600) {
          whiteTile4.center.y = -71
          greyTile4.center.y = -71
          blackTile4.center.y = -71
          colorText4.center.y = -142
          random12 = ofTwelve()
          var colorw4 = colorarray[random12]
          var colorwordw4 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorg4 = colorarray[random12]
          var colorwordg4 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorb4 = colorarray[random12]
          var colorwordb4 = colorwordsarray[random12]
          var word4array = [colorwordw4, colorwordg4, colorwordb4]
          var word4 = word4array [ofThree()]
          whiteTile4.backgroundColor = colorw4
          greyTile4.backgroundColor = colorg4
          blackTile4.backgroundColor = colorb4
          [self.view .bringSubviewToFront(colorText4)]
          colorText4.text = word4
          colorText4.hidden = false
  
  
      }
      if (whiteTile5.center.y &gt;= 600) {
          whiteTile5.center.y = -71
          greyTile5.center.y = -71
          blackTile5.center.y = -71
          colorText5.center.y = -142
          random12 = ofTwelve()
          var colorw5 = colorarray[random12]
          var colorwordw5 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorg5 = colorarray[random12]
          var colorwordg5 = colorwordsarray[random12]
          random12 = ofTwelve()
          var colorb5 = colorarray[random12]
          var colorwordb5 = colorwordsarray[random12]
          var word5array = [colorwordw5, colorwordg5, colorwordb5]
          var word5 = word5array [ofThree()]
          whiteTile5.backgroundColor = colorw5
          greyTile5.backgroundColor = colorg5
          blackTile5.backgroundColor = colorb5
          [self.view .bringSubviewToFront(colorText5)]
          colorText5.text = word5
          colorText5.hidden = false
      }
  
      }
  
  
  
  
  
  
  
  
  // Below are the button actions.  First they check if the correct color was selected.  If false, no action.  If true, it moves all tiles down and selects a new color randomly and updates the label accordingly.  After that, it calls the RandomPlacement function that scrambles the order of the next row of tiles displayed.
  
  
  
  
      @IBAction func White4Action(sender: AnyObject) {
  //        if (whiteTile4.center.y &gt;= 490 &amp;&amp; word == "White") {
  
          if (word4 == colorwordw4){
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFive()]
  
  
          }
  
  
  
  
  
      }
      @IBAction func Grey4Action(sender: AnyObject) {
  
          if (word4 == colorwordg4) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFive()]
  
          }
  
  
  
      }
  
      @IBAction func Black4Action(sender: AnyObject) {
  
          if (word4 == colorwordb4) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFive()]
          }
  
  
  
      }
  
  
      @IBAction func White3Action(sender: AnyObject) {
  
          if (word3 == colorwordw3){
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFour()]
  
  
  
          }
  
  
  
      }
      @IBAction func Grey3Action(sender: AnyObject) {
  
          if (word3 == colorwordg3) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFour()]
  
  
  
          }
  
  
  
      }
      @IBAction func Black3Action(sender: AnyObject) {
  
          if (word3 == colorwordb3) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementFour()]
  
          }
  
  
  
      }
  
      @IBAction func White2Action(sender: AnyObject) {
  
          if (word2 == colorwordw2) {
  
              [moveTilesDown()]
  
  
              [RandomPlacementThree()]
  
  
          }
  
  
  
      }
  
      @IBAction func Grey2Action(sender: AnyObject) {
  
          if (word2 == colorwordg2) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementThree()]
  
  
          }
  
  
  
      }
  
      @IBAction func Black2Action(sender: AnyObject) {
  
          if (word2 == colorwordb2) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementThree()]
  
  
          }
  
  
  
      }
  
      @IBAction func White1Action(sender: AnyObject) {
  
          if (word1 == colorwordw1) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementTwo()]
  
  
           }
  
      }
      @IBAction func Grey1Action(sender: AnyObject) {
  
          if (word1 == colorwordg1) {
  
              [moveTilesDown()]
  
  
              [RandomPlacementTwo()]
  
  
        }
  
      }
  
      @IBAction func Black1Action(sender: AnyObject) {
  
          if (word1 == colorwordb1) {
  
              [moveTilesDown()]
  
  
              [RandomPlacementTwo()]
  
  
               }
  
      }
  
      @IBAction func White5Action(sender: AnyObject) {
  
  
          if (word5 == colorwordw5) {
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementOne()]
  
  
          }
      }
  
  
      @IBAction func Grey5Action(sender: AnyObject) {
  
          if (word5 == colorwordg5) {
  
  
  
              [moveTilesDown()]
  
  
              [RandomPlacementOne()]
  
  
  
  
      }
      }
  
  
      @IBAction func Black5Action(sender: AnyObject) {
  
          if (word5 == colorwordb5) {
  
  
  
  
          [moveTilesDown()]
  
              [RandomPlacementOne()]
  
          }
  
  
  
  }
  
  
  
      func RandomPlacementOne(){
  
  
          // question = wordarray[ofThree()]
  
  
          var RandomNumber = arc4random() % 6
          switch(RandomNumber){
          case 0:
              blackTile1.center.x = 161
              whiteTile1.center.x = 268
              greyTile1.center.x = 54
  
  
          case 1:
              blackTile1.center.x = 268
              whiteTile1.center.x = 161
              greyTile1.center.x = 54
  
  
          case 2:
              blackTile1.center.x = 54
              whiteTile1.center.x = 268
              greyTile1.center.x = 161
  
  
          case 3:
              blackTile1.center.x = 54
              whiteTile1.center.x = 161
              greyTile1.center.x = 268
  
  
          case 4:
              blackTile1.center.x = 268
              whiteTile1.center.x = 54
              greyTile1.center.x = 161
  
  
          case 5:
              blackTile1.center.x = 161
              whiteTile1.center.x = 54
              greyTile1.center.x = 268
  
  
          default: break
  
  
  
      }
  //         [colorWord()]
  
  }
  
  
      // Below are the random placement functions.  It first chooses a random number out of 6 and depending on the number, reorders the colors on the row.
  
      func RandomPlacementTwo(){
  
  
          // question = wordarray[ofThree()]
  
  
          var RandomNumber = arc4random() % 6
          switch(RandomNumber){
          case 0:
              blackTile2.center.x = 161
              whiteTile2.center.x = 268
              greyTile2.center.x = 54
  
  
          case 1:
              blackTile2.center.x = 268
              whiteTile2.center.x = 161
              greyTile2.center.x = 54
  
  
          case 2:
              blackTile2.center.x = 54
              whiteTile2.center.x = 268
              greyTile2.center.x = 161
  
  
          case 3:
              blackTile2.center.x = 54
              whiteTile2.center.x = 161
              greyTile2.center.x = 268
  
  
          case 4:
              blackTile2.center.x = 268
              whiteTile2.center.x = 54
              greyTile2.center.x = 161
  
  
          case 5:
              blackTile2.center.x = 161
              whiteTile2.center.x = 54
              greyTile2.center.x = 268
  
  
          default: break
  
  
  
          }
  //         [colorWord()]
  
  }
      func RandomPlacementThree(){
  
  
          // question = wordarray[ofThree()]
  
  
          var RandomNumber = arc4random() % 6
          switch(RandomNumber){
          case 0:
              blackTile3.center.x = 161
              whiteTile3.center.x = 268
              greyTile3.center.x = 54
  
  
          case 1:
              blackTile3.center.x = 268
              whiteTile3.center.x = 161
              greyTile3.center.x = 54
  
  
          case 2:
              blackTile3.center.x = 54
              whiteTile3.center.x = 268
              greyTile3.center.x = 161
  
  
          case 3:
              blackTile3.center.x = 54
              whiteTile3.center.x = 161
              greyTile3.center.x = 268
  
  
          case 4:
              blackTile3.center.x = 268
              whiteTile3.center.x = 54
              greyTile3.center.x = 161
  
  
          case 5:
              blackTile3.center.x = 161
              whiteTile3.center.x = 54
              greyTile3.center.x = 268
  
  
          default: break
  
  
  
          }
  
  //         [colorWord()]
  
  }
      func RandomPlacementFour(){
  
  
  
          // question = wordarray[ofThree()]
  
  
          var RandomNumber = arc4random() % 6
          switch(RandomNumber){
          case 0:
              blackTile4.center.x = 161
              whiteTile4.center.x = 268
              greyTile4.center.x = 54
  
  
          case 1:
              blackTile4.center.x = 268
              whiteTile4.center.x = 161
              greyTile4.center.x = 54
  
  
          case 2:
              blackTile4.center.x = 54
              whiteTile4.center.x = 268
              greyTile4.center.x = 161
  
  
          case 3:
              blackTile4.center.x = 54
              whiteTile4.center.x = 161
              greyTile4.center.x = 268
  
  
          case 4:
              blackTile4.center.x = 268
              whiteTile4.center.x = 54
              greyTile4.center.x = 161
  
  
          case 5:
              blackTile4.center.x = 161
              whiteTile4.center.x = 54
              greyTile4.center.x = 268
  
  
          default: break
  
  
  
          }
  
  // [colorWord()]
  }
      func RandomPlacementFive(){
  
          // question = wordarray[ofThree()]
  
  
          var RandomNumber = arc4random() % 6
          switch(RandomNumber){
          case 0:
              blackTile5.center.x = 161
              whiteTile5.center.x = 268
              greyTile5.center.x = 54
  
  
          case 1:
              blackTile5.center.x = 268
              whiteTile5.center.x = 161
              greyTile5.center.x = 54
  
  
          case 2:
              blackTile5.center.x = 54
              whiteTile5.center.x = 268
              greyTile5.center.x = 161
  
  
          case 3:
              blackTile5.center.x = 54
              whiteTile5.center.x = 161
              greyTile5.center.x = 268
  
  
          case 4:
              blackTile5.center.x = 268
              whiteTile5.center.x = 54
              greyTile5.center.x = 161
  
  
          case 5:
              blackTile5.center.x = 161
              whiteTile5.center.x = 54
              greyTile5.center.x = 268
  
  
          default: break
  
  
  
          }
  //        [colorWord()]
  
  
  }
  
  }
  </code></pre>