0
0
Swiftprogramming~20 mins

Swift REPL and Playgrounds - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swift REPL and Playgrounds Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Swift REPL variable mutation
What is the output of the following Swift REPL code snippet?
Swift
var greeting = "Hello"
greeting += ", world!"
print(greeting)
AHello, world
BHello world
CHello world!
DHello, world!
Attempts:
2 left
💡 Hint
Look carefully at the string concatenation and punctuation.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Swift Playgrounds
Which of the following best describes the main purpose of Swift Playgrounds?
ATo compile large Swift projects for production
BTo write and test Swift code interactively with immediate feedback
CTo manage Swift package dependencies
DTo deploy Swift apps to the App Store
Attempts:
2 left
💡 Hint
Think about what makes Playgrounds different from full IDEs.
Predict Output
advanced
2:00remaining
Output of Swift REPL code with optional binding
What is the output of this Swift REPL code?
Swift
let numberString: String? = "42"
if let number = numberString, number == "42" {
    print("Number is 42")
} else {
    print("Number is not 42")
}
ACompilation error
BNumber is not 42
CNumber is 42
DRuntime error
Attempts:
2 left
💡 Hint
Check the optional binding and string comparison carefully.
🔧 Debug
advanced
2:00remaining
Identify the error in Swift Playground code
What error will this Swift Playground code produce?
Swift
var count = 5
count = "five"
print(count)
AType error: Cannot assign value of type 'String' to type 'Int'
BRuntime error: Unexpected nil value
CSyntax error: Missing semicolon
DNo error, prints 'five'
Attempts:
2 left
💡 Hint
Check the variable type and assignment compatibility.
🚀 Application
expert
2:30remaining
Result of running Swift Playground code with closures
What is the output of this Swift Playground code snippet?
Swift
let numbers = [1, 2, 3, 4, 5]
let doubled = numbers.map { num in
    num * 2
}
print(doubled)
A[2, 4, 6, 8, 10]
B[1, 2, 3, 4, 5]
CCompilation error due to missing return
DRuntime error: nil value
Attempts:
2 left
💡 Hint
Remember how the map function transforms each element.