0
0
Swiftprogramming~10 mins

String is a value type behavior 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 create a new string variable.

Swift
var greeting = "Hello"
var newGreeting = [1]
Drag options to blanks, or click blank then click option'
Agreeting
B*greeting
C&greeting
Dgreeting()
Attempts:
3 left
💡 Hint
Common Mistakes
Using & or * which are not used for copying in Swift.
Trying to call the variable as a function.
2fill in blank
medium

Complete the code to change the copy without affecting the original string.

Swift
var original = "Swift"
var copy = original
copy[1]"SwiftLang"
Drag options to blanks, or click blank then click option'
A ==
B +=
C+
D =
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators like == instead of assignment.
Using += which appends instead of replacing.
3fill in blank
hard

Fix the error in the code to correctly copy and modify the string.

Swift
var text1 = "Hello"
var text2 = text1
text2.append([1])
Drag options to blanks, or click blank then click option'
A5
B" World"
CWorld
D' World'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which are not valid for strings in Swift.
Passing a number instead of a string.
4fill in blank
hard

Fill both blanks to create a copy and check if original and copy are equal.

Swift
var first = "Apple"
var second = [1]
let areEqual = first [2] second
Drag options to blanks, or click blank then click option'
Afirst
B==
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of == for comparison.
Using != which checks inequality.
5fill in blank
hard

Fill all three blanks to copy a string, modify the copy, and print both strings.

Swift
var original = "Cat"
var copy = [1]
copy.append([2])
print(original, [3])
Drag options to blanks, or click blank then click option'
Aoriginal
B"s"
Ccopy
Doriginal.append("s")
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to append to original instead of copy.
Printing only one variable.