Game Overview
Part of the Fundamentals section of Coddy's Swift journey — lesson 58 of 86.
Challenge
EasyIn this chapter, you'll build a customizable FizzBuzz game step by step.
Read a single number from input and determine what to print based on the classic FizzBuzz rules:
- If the number is divisible by both 3 and 5, print
FizzBuzz - If the number is divisible by 3 only, print
Fizz - If the number is divisible by 5 only, print
Buzz - Otherwise, print the number itself
You will receive the following input:
- A single integer
For example, if the input is 15, the output should be:
FizzBuzzIf the input is 9, the output should be:
FizzIf the input is 7, the output should be:
7Try it yourself
// Read input
let number = Int(readLine()!)!
// TODO: Write your code below to implement FizzBuzz logic
// Check divisibility by 3 and 5, then print the appropriate resultAll 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