Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, world!".
Swift
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the text.
Using single quotes instead of double quotes.
✗ Incorrect
In Swift, to print text, you use the print function with the text inside double quotes.
2fill in blank
mediumComplete the code to print the value of the variable name.
Swift
let name = "Alice" print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable name.
Trying to call print inside print.
✗ Incorrect
To print the value of a variable, just pass the variable name without quotes to print.
3fill in blank
hardFix the error in the print statement to correctly print the sum of 5 and 3.
Swift
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the expression inside quotes.
Using a function sum that does not exist.
✗ Incorrect
To print the sum, write the expression 5 + 3 inside print without quotes.
4fill in blank
hardFill both blanks to print the message with the variable age.
Swift
let age = 10 print([1] + [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable age inside quotes.
Using the number 10 instead of the variable.
✗ Incorrect
Use a string "Age: " and the variable age to print them together.
5fill in blank
hardFill all three blanks to print the full sentence with name and age.
Swift
let name = "Bob" let age = 25 print([1] + ", is " + [2] + " years old.")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variables which prints their names, not values.
Using string literals instead of variables.
✗ Incorrect
Use the variable name and age to build the sentence.