Menu
Coddy logo textTech

Recap - Simple Logic

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

challenge icon

Challenge

Easy

Determine whether a customer qualifies for a special loyalty reward by combining multiple conditions using comparison and logical operators.

You are provided with the following variables:

purchase_amount <- 150
years_as_customer <- 3
has_loyalty_card <- TRUE
items_bought <- 7
is_holiday_season <- FALSE

Use comparison and logical operators to create the following variables:

  1. Create a variable called big_spender that stores TRUE if the purchase amount is greater than or equal to 100 AND the customer has a loyalty card
  2. Create a variable called loyal_customer that stores TRUE if the customer has been a customer for 5 or more years OR has a loyalty card
  3. Create a variable called qualifies_for_gift that stores TRUE if the customer bought more than 5 items AND the purchase amount is greater than 100 AND it is NOT the holiday season
  4. Create a variable called gets_bonus_points that stores TRUE if the customer is a big spender (purchase amount >= 100) AND has been a customer for at least 2 years AND has a loyalty card
  5. Create a variable called special_reward that stores TRUE if the customer qualifies for any of these: (purchase amount > 200) OR (years as customer >= 5 AND has loyalty card) OR (items bought >= 10)

Use the print() function to display big_spender, loyal_customer, qualifies_for_gift, gets_bonus_points, and special_reward in that exact order.

Try it yourself

# Given variables - DO NOT MODIFY
purchase_amount <- 150
years_as_customer <- 3
has_loyalty_card <- TRUE
items_bought <- 7
is_holiday_season <- FALSE

# TODO: Write your code below
# Create the following variables using comparison and logical operators:
# 1. big_spender - TRUE if purchase_amount >= 100 AND has_loyalty_card
# 2. loyal_customer - TRUE if years_as_customer >= 5 OR has_loyalty_card
# 3. qualifies_for_gift - TRUE if items_bought > 5 AND purchase_amount > 100 AND NOT is_holiday_season
# 4. gets_bonus_points - TRUE if purchase_amount >= 100 AND years_as_customer >= 2 AND has_loyalty_card
# 5. special_reward - TRUE if (purchase_amount > 200) OR (years_as_customer >= 5 AND has_loyalty_card) OR (items_bought >= 10)



# Output the results
print(big_spender)
print(loyal_customer)
print(qualifies_for_gift)
print(gets_bonus_points)
print(special_reward)

All lessons in Fundamentals