NEW: Learn SwiftUI with my free YouTube video series! >>

Spot the error

This Swift code contains one error – can you select the line that is incorrect?

Tip: You should mentally run the code from top to bottom, meaning that if line 3 says an integer should be returned and line 10 tries to return a string, line 10 is the wrong one.

func performExercise(times: Int, type: String) -> String {
    var result: String = ""
    for _ in 0 ..< times {
        result +="I'm doing a \(type)\n"
    }
    if times < 10 {
        result += "That was easy!"
    } else if times < 30 {
        result += "That was challenging!"
    } else {
        result += "Phew - I need a break!"
    }
    return result
}
print(performExercise(times: 19, type: "deadlift"))
MASTER SWIFT NOW
Buy Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code