• 20 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 3/6/20

Optimize your code with functions

Log in or subscribe for free to enjoy all this course has to offer!

Evaluated skills

  • Create functions in Swift
  • Question 1

    Which keyword is used to declare a function?

    • var

       

    • func

       

    • function

    • funk

  • Question 2

    Select the correct function declarations:

    Careful, there are several correct answers.
    • func hello() {
      print("Hello")
      }
    • func hello {
      print("Hello")
      }
    • func hello() -> String {
      print("Hello")
      }
    • func hello() -> String {
      return "Hello"
      }
    • func hello() -> Int {
      return "Hello"
      }
  • Question 3

    In which context does the variable message exist in the following example?

    var names = ["Jenny", "Livia", "Paul"]
    func hello() {
    var message = "Welcome "
    for name in names {
    message + = name + ", "
    }
    print(message)
    }

     

    Careful, there are several correct answers.
    • In the overall context of the file

       

    • In the hello function

    • In the for-in loop

    • It's not accessible in this code, and shouldn't be used