0
0
Swiftprogramming~10 mins

Why let and var distinction matters in Swift - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a constant in Swift.

Swift
let number = [1]
Drag options to blanks, or click blank then click option'
A10
Bvar
Clet
D"ten"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'var' instead of a value
Assigning a string instead of a number
2fill in blank
medium

Complete the code to declare a variable in Swift.

Swift
var name = [1]
Drag options to blanks, or click blank then click option'
A10
Bvar
Clet
D"Alice"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'let' instead of a value
Assigning a number instead of a string
3fill in blank
hard

Fix the error in the code by choosing the correct keyword to allow changing the value.

Swift
[1] score = 5
score = 10
Drag options to blanks, or click blank then click option'
Ascore
B10
Cvar
Dlet
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'let'
Choosing a value like '10' instead of the keyword
Choosing 'score'
4fill in blank
hard

Choose the keyword that allows mutating the array by appending an element.

Swift
[1] scores = [85, 90]
scores.append(95)
Drag options to blanks, or click blank then click option'
Alet
Bvar
Cconstant
Dfinal
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'let'
Using non-Swift keywords like 'constant'
5fill in blank
hard

Choose the keyword that allows the function to modify the counter.

Swift
[1] counter = 0

func incrementCounter() {
  counter += 1
}

incrementCounter()
print(counter)
Drag options to blanks, or click blank then click option'
Avar
Bstatic let
Clet
Dprivate var
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'let'
Adding unnecessary modifiers like 'static' or 'private'