Game Overview
Part of the Fundamentals section of Coddy's R journey — lesson 52 of 78.
Challenge
EasyIn this chapter, you'll build a customizable FizzBuzz game using functions, loops, and conditional logic.
To start, create a function called check_divisible that takes two arguments: number and divisor. The function should return TRUE if the number is divisible by the divisor (no remainder), and FALSE otherwise.
Read two numbers from input, convert them to numeric values, and call your function with these values. Print the returned result.
For example, if the inputs are:
15
3The output should be:
[1] TRUEIf the inputs are:
15
5The output should be:
[1] TRUEIf the inputs are:
7
3The output should be:
[1] FALSETry it yourself
# Read input
con <- file("stdin", "r")
number <- as.numeric(suppressWarnings(readLines(con, n = 1)))
divisor <- as.numeric(suppressWarnings(readLines(con, n = 1)))
# TODO: Create a function called check_divisible that takes two arguments:
# number and divisor. Return TRUE if number is divisible by divisor, FALSE otherwise.
# Call your function and print the result
print(check_divisible(number, divisor))All lessons in Fundamentals
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values