0
0
Swiftprogramming~10 mins

What is Swift - Interactive Quiz & Practice

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

Complete the code to print a greeting in Swift.

Swift
print([1])
Drag options to blanks, or click blank then click option'
AHello Swift
BHello, Swift!
C'Hello, Swift!'
D"Hello, Swift!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
2fill in blank
medium

Complete the code to declare a variable named greeting with the value "Hello".

Swift
var greeting = [1]
Drag options to blanks, or click blank then click option'
A"Hello"
B'Hello'
CHello
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the string without quotes.
Using single quotes instead of double quotes.
3fill in blank
hard

Fix the error in the code to correctly declare a constant named pi with value 3.14.

Swift
let pi = [1]
Drag options to blanks, or click blank then click option'
A3,14
B"3.14"
C3.14
Dpi
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma instead of a dot for decimals.
Putting the number inside quotes making it a string.
4fill in blank
hard

Fill both blanks to create a function named greet that prints a message.

Swift
func [1]() {
    print([2])
}
Drag options to blanks, or click blank then click option'
Agreet
B"Welcome to Swift!"
Cgreeting
DWelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a string in print.
Missing parentheses after the function name.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys and values.

Swift
let [1] = [[2]: [3]]
Drag options to blanks, or click blank then click option'
Aperson
B"name"
C"Alice"
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string keys or values.
Using a variable name instead of a string for the key.