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 trial

Cayman Lowe
1,094 PointsAssigning color output to if else statements
Like the example here with playing cards. If I instead wanted to output a specific color (visually) to the console instead of a number, how would I go about doing that?
2 Answers

Cayman Lowe
1,094 PointsI'm in the beginning stages of programming an app that has visual indicators of various colors depending on the output of variables. Just looking for general advice on ways to accomplish this

Dominic Bryan
14,452 PointsI am not sure in the the way you want your variables and I ma going to assume you have to a view that you can alter. Although if it was a label or text view it would work in the same manner. But here is a working swift program i type in 2 seconds that depending on what totalNumber is equal to, depends on the colour of the background of the view.
//
// ViewController.swift
// colourChange
//
import UIKit
class ViewController: UIViewController {
var firstNumber = 2
var secondNumber = 3
override func viewDidLoad() {
super.viewDidLoad()
var totalNumber = firstNumber + secondNumber
if totalNumber == 5 {
self.view.backgroundColor = UIColor.blueColor()
}else{
self.view.backgroundColor = UIColor.greenColor()
}
}
}
you can simply just copy and paste this into a empty swift file in a project or I have uploaded this to GitHub if you want to look at it that way, just download the zip and open up: https://github.com/dombryan94/colourChange
Hope this helps, ask if you want anything else and remember to mark this up for others to see (and it helps me out a lot) :)
Thanks
Dom
Dominic Bryan
14,452 PointsDominic Bryan
14,452 PointsI am not sure what you are asking, because the console can not print colors its like a CMD line, just black and white text.
If you can specify im sure I can help
Dom