Swift
- Boolean
- String interpolation
- Project: convert C to F
import Cocoa // boolean
var gameOver = false
print(gameOver)
gameOver.toggle()
print(gameOver) // join string
var name = "john" + " " + "doe"
// use string interpolation
let firstName = "john"
let lastName = "doe"
let age = 25
let fullName = "full name is \(firstName) \(lastName), and he is \(age) years old" // check point
/*
Creates a constant holding any temperature in Celsius.
Converts it to Fahrenheit by multiplying by 9, dividing by 5, then adding 32.
Prints the result for the user, showing both the Celsius and Fahrenheit values.
*/ let tempC = 21
let tempF = tempC * 9 / 5 + 32
print("\(tempC) Celsius is \(tempF) in Fahrenheit")
Discover more from Coursity
Subscribe to get the latest posts sent to your email.