0
0
Swiftprogramming~10 mins

Let for constants (immutable) in Swift - Interactive Code Practice

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

Complete the code to declare a constant named pi with the value 3.14.

Swift
let [1] = 3.14
Drag options to blanks, or click blank then click option'
Api
Bvar
Cradius
Darea
Attempts:
3 left
💡 Hint
Common Mistakes
Using var instead of let for constants.
Choosing a variable name instead of a constant name.
2fill in blank
medium

Complete the code to declare a constant maxScore with the integer value 100.

Swift
let [1] = 100
Drag options to blanks, or click blank then click option'
Ascore
BscoreMax
Cmax
DmaxScore
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than maxScore.
Using var instead of let.
3fill in blank
hard

Fix the error by completing the code to declare a constant greeting with the value "Hello".

Swift
let [1] = "Hello"
Drag options to blanks, or click blank then click option'
Alet greeting
Bgreeting
Cvar greeting
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Writing let let greeting or var greeting instead of just the name.
Omitting the constant name.
4fill in blank
hard

Fill both blanks to declare a constant speedLimit with the value 60 and print it.

Swift
let [1] = 60
print([2])
Drag options to blanks, or click blank then click option'
AspeedLimit
Bspeed
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for declaration and print.
Using var instead of let.
5fill in blank
hard

Fill all three blanks to declare constants width and height with values 10 and 20, then print their sum.

Swift
let [1] = 10
let [2] = 20
print([3] + [2])
Drag options to blanks, or click blank then click option'
Awidth
Bheight
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong names like length.
Mixing variable and constant declarations.