App Development with swift question

Hey Swift forums I have been having trouble with an exercise on the book App development with swift book. With unit 2 section 2 on one of the exercises. Ive been getting some errors... I have checked through the book and google and cannot find a fix for the problem. Thank you for any help, I figured I can check here before searching YouTube.



Exercise - Parameters and Argument Labels

Write a new introduction function called introduction. It should take two String parameters, name and home, and one Int parameter, age. The function should print a brief introduction. I.e. if "Mary," "California," and 32 were passed into the function, it might print "Mary, 32, is from California." Call the function and observe the printout.

func introduction() {
    
    name; String() = "Daniel";
    String; home = "Richfield";
    Int(); = 19;
}
print introduction


What you have written isn't really Swift code, it's something else entirely :stuck_out_tongue:

Lets break it down, first point is: "Write a new function called introduction. It should take two String parameters, name and home, and one Int parameter, age."

func introduction(name: String, home: String, age: Int) {
    
}

Next: The function should print a brief introduction I.e if "Mary", "California" and 32 were passed into the function, it might print "Mary, 32, is from California."

func introduction(name: String, home: String, age: Int) {
    print("\(name), \(age), is from \(home)")
}

Finally: Call the function and observe the printout

func introduction(name: String, home: String, age: Int) {
    print("\(name), \(age), is from \(home)")
}

introduction(name: "fiberly", home: "Swift Forums", age: 100)
1 Like

thanks for the help Buckley brined perfectly!

Of course, if you'd looked at the Swift language reference yourself, you would have seen what was wrong. The best way to learn anything is to study it yourself, not ask others to provide the answers

1 Like
Terms of Service

Privacy Policy

Cookie Policy