Recap - True or False
Part of the Fundamentals section of Coddy's Swift journey — lesson 36 of 86.
Challenge
EasyRead a string input and determine whether it represents a "truthy" or "falsy" value.
You will receive the following input:
- A single line containing a string (e.g.,
"yes","no","1","0")
Use readLine() to read the input and safely unwrap it with if let. Then check the value:
- If the input is
"yes","true", or"1", printtrue - If the input is
"no","false", or"0", printfalse
Print: Either true or false based on the input value
Try it yourself
// Read input
if let input = readLine() {
// TODO: Write your code below
// Check if input is "yes", "true", "1" -> print true
// Check if input is "no", "false", "0" -> print false
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorCompound AssignmentRecap - Simple MathComparison Operators7Basic IO
Print FunctionString InterpolationReadLine InputType ConversionRecap - Till 120Recap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesArgument LabelsRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Sequences
Iterating Over ElementsThe Enumerated MethodIterating Over Strings P1Iterating Over Strings P22Variables
Let vs VarType AnnotationsNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting Input3Optionals
What Are OptionalsUnwrapping With If LetGuard LetNil Coalescing OperatorRecap - Safe Unwrapping9Loops
For-In LoopWhile LoopRepeat-While LoopBreakContinueRecap - FactorialRanges In LoopsNested LoopRecap - Dynamic Input