Ruby Exercises
Getting Started
Fork and clone this repository
Run
bundle install
to install dependenciesRun
rubocop
to lint your codeRun
ruby lib/file_name.rb
to run your file
Requirements
Complete each challenge in a separate file.
Challenge 1 - Calculator
Create a simple calculator that first asks the user what method they would like to use (addition, subtraction, multiplication, division) and then asks the user for two numbers, returning the result of the method with the two numbers. Here is a sample prompt:
Challenge 2 - Reverse a string
Reverse a string in place. In other words, do not create a new string or use other methods on the string such as reverse
. The goal of the problem is to use a loop and the string accessors to figure out which values to swap for other values. Below is some sample output.
Challenge 3 - Bank Transactions
Create a prompt that asks the user if they would like to display their balance, withdraw or deposit. Write three methods to perform these calculations and output the result to the user. Here is a sample output:
Challenge 4 - Guessing Game
Create a program that asks the user to guess a number between 1 and 100. Once the user guesses a number, the program should say, higher, lower, or tell the user that he got the number correct. The user should continue to make guesses until he guesses correctly. Also, once the user guesses correctly, the program should print the number of guesses needed to arrive at the correct answer. Below is sample output:
Licensing
All content is licensed under a CC-BY-NC-SA 4.0 license.
All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.
Last updated