Menu
Coddy logo textTech

Game Overview

Part of the Fundamentals section of Coddy's R journey — lesson 52 of 78.

challenge icon

Challenge

Easy

In 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
3

The output should be:

[1] TRUE

If the inputs are:

15
5

The output should be:

[1] TRUE

If the inputs are:

7
3

The output should be:

[1] FALSE

Try 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