0
0
Swiftprogramming~10 mins

Print function for output 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 print "Hello, world!".

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

Complete 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'
Aname
Bprint(name)
C"name"
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable name.
Trying to call print inside print.
3fill in blank
hard

Fix 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'
A5 + 3
B"5 + 3"
C5 plus 3
Dsum(5, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the expression inside quotes.
Using a function sum that does not exist.
4fill in blank
hard

Fill 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'
A"Age: "
Bage
C"age"
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable age inside quotes.
Using the number 10 instead of the variable.
5fill in blank
hard

Fill 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'
Aname
Bage
C"Bob"
D"25"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variables which prints their names, not values.
Using string literals instead of variables.