Challenge - 5 Problems
Swift REPL and Playgrounds Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Look carefully at the string concatenation and punctuation.
✗ Incorrect
The variable greeting starts as "Hello" and then ", world!" is appended, resulting in "Hello, world!".
🧠 Conceptual
intermediate1:30remaining
Purpose of Swift Playgrounds
Which of the following best describes the main purpose of Swift Playgrounds?
Attempts:
2 left
💡 Hint
Think about what makes Playgrounds different from full IDEs.
✗ Incorrect
Swift Playgrounds is designed for learning and experimenting with Swift code interactively, giving immediate results.
❓ Predict Output
advanced2: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") }
Attempts:
2 left
💡 Hint
Check the optional binding and string comparison carefully.
✗ Incorrect
The optional string contains "42", so the if condition is true and prints "Number is 42".
🔧 Debug
advanced2:00remaining
Identify the error in Swift Playground code
What error will this Swift Playground code produce?
Swift
var count = 5 count = "five" print(count)
Attempts:
2 left
💡 Hint
Check the variable type and assignment compatibility.
✗ Incorrect
Variable count is declared as Int, but assigned a String, causing a type error.
🚀 Application
expert2: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)
Attempts:
2 left
💡 Hint
Remember how the map function transforms each element.
✗ Incorrect
The map function doubles each number, resulting in [2, 4, 6, 8, 10].