Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a greeting in Swift.
Swift
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
✗ Incorrect
In Swift, strings must be enclosed in double quotes when printed.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the string without quotes.
Using single quotes instead of double quotes.
✗ Incorrect
In Swift, string values must be enclosed in double quotes when assigned to variables.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma instead of a dot for decimals.
Putting the number inside quotes making it a string.
✗ Incorrect
Numbers in Swift use a dot for decimals, not a comma.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a string in print.
Missing parentheses after the function name.
✗ Incorrect
The function name is greet and it prints the string "Welcome to Swift!".
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string keys or values.
Using a variable name instead of a string for the key.
✗ Incorrect
This creates a dictionary named person with key "name" and value "Alice".