day 4 Flashcards

1
Q

arc4random()

A

generates a random number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

func syntax

A
func nameOfFunction() {
    // body of function goes here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

function type

A
func sayHelloToStudent(student: String) {
    print("Hello \(student)")
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

multiple func paramters

A

greetStudent(student: String, school: String)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

multiple func paramters example

A
func averageScore(firstScore: Double, secondScore: Double, thirdScore: Double) {
    let totalScore = firstScore + secondScore + thirdScore
    print(totalScore / 3)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To return a value from a function

A
func calculateTip(priceOfMeal: Double) -> Double {
    return priceOfMeal * 0.15
}
func isPastBedtime(hour: Int) -> Bool {
    if hour > 9 {
        return true
    } else {
        return false
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

boolean

A
var name=True
print(name)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

if true do something

A

if true{print(“hi”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

if statement needs

A

boolean to check

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

else only executes

A

if condition false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

else if

A

to add extra conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

else statement always

A

last statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

user input

A

readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

var password=

A

readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

while code

A

while true{print(“hi”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to specify return value

A

->Int{}

17
Q

return add

A
func add()->Int{
var number=1+1
return number
}
18
Q

end of year bonus

A
func endOfYearBonus(basePay: Double, bonus: Double,percentBonus: Double)->(Double){
    let percentBonus=0.10
    return basePay + bonus + (basePay * percentBonus)
}
19
Q

Internal and External Parameter Names

A
func addValues(value1 x: Int, value2 y: Int) -> Int {
    // internally, use `x` and `y`
    return x + y
}
// externally, use `value1` and `value2`
addValues(value1: 5, value2: 10)
20
Q

Omitting External Parameter Names example

A
func combineStrings(_ s1: String, _ s2: String) -> String {
    return s1 + s2
}

combineStrings(“We love”, “ Swift!”)