March 25 - Build a Dice Validator in Ruby
Building validations in programs is a common requirement. In this exercise we'll examine how to ensure a set of dice are valid by implementing a method that returns false if the dice are outside the range of 1-6.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Build a dice validator program.

Exercise Description

Implement a program that checks to see if a roll of two dice is valid or not.

Example Input/Output

valid_dice? 4, 2 # => true
valid_dice? 6, 6 # => true
valid_dice? 5, 1 # => true
valid_dice? 8, 2 # => false
valid_dice? 1, 7 # => false
valid_dice? 9, 7 # => false

Real World Usage

Working with range based validations are a common requirement for a wide variety of applications. Imagine a situation where you need to see if a user's zip code falls inside of a certain range of numbers. There are a number of ways to implement this solution, I personally opted for the version that worked with collections of data.

Test Cases

Code File