Select Page

Optionals Example Code

// 2 ways to print the highest score… var studentsAndScores = [”Amy”: 88, “James”: 55, “Helen”: 99] func highestScore(scores: [String: Int]) { //OPTION 1 BELOW HERE! let a = studentsAndScores [”Amy”]!...

IF – THEN Percentage Example

This sample code checks to see if a given year is a LEAP year… var aYear = Int.self func isLeap(year: Int) { var leap = “NO” //IF divisible by 4 with no remainders. if year % 4 == 0 { leap = “YES” //Is leap year, unless: } if year % 100...

Function Code Calculation Example

func calculator() { let a = Int(readLine()!)! //First input let b = Int(readLine()!)! //Second input add(n1: a, n2: b) subtract(n1: a, n2: b) multiply(n1: a, n2: b) divide(n1: a, n2: b) } func add(n1: Int,n2: Int) { print(n1 + n2) } add(n1: 3, n2: 4) func subtract(n1:...