• 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 4/27/23

Optimize your code with functions

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

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best