• 20 heures
  • Moyenne

Ce cours est visible gratuitement en ligne.

course.header.alt.is_video

course.header.alt.is_certifying

J'ai tout compris !

Mis à jour le 27/04/2023

Optimize your code with functions

Compétences évaluées

  • 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:

    Attention, plusieurs réponses sont possibles.
    • 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)
    }

     

    Attention, plusieurs réponses sont possibles.
    • 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

Et si vous obteniez un diplôme OpenClassrooms ?
  • Formations jusqu’à 100 % financées
  • Date de début flexible
  • Projets professionnalisants
  • Mentorat individuel
Trouvez la formation et le financement faits pour vous