Chapters 14 & 15 - Web Apps
Exercise 1: Sinatra routes
The roll_die
method below simulates rolling a die with the given number of sides. If you call roll_die(6)
, you’ll get a random number between 1 and 6. If you call roll_die(20)
, you’ll get a random number between 1 and 20.
Create three Sinatra routes that use this method:
- The
/roll/4
path should output “Rolling 4 sided die:”, followed by the result of callingroll_die(4)
. - The
/roll/6
path should output “Rolling 6 sided die:”, followed by the result of callingroll_die(6)
. - The
/roll/20
path should output “Rolling 20 sided die:”, followed by the result of callingroll_die(20)
.
Once you have your server running, you can load any of these paths, and then refresh the browser repeatedly to get different random numbers.