Scripts and Methods Exercises

  1. Create a new file, methods_exercises.rb. Define the following methods in this script:

  2. Write a method #print_thrice, that accepts a string as an argument. It should puts that string 3 times.

     def print_thrice(string)
       # Your code here
     end
    
  3. Write a method, #print_thrice_thrice, that also accepts a string as an argument. It should call print_thrice with that string three times (for 9 total prints).

  4. Write a method, #add_multiply_subtract, that accepts two integers as arguments. Your method should do the following:

    • add the two numbers
    • multiply the two numbers
    • subtract the sum from the product
    • puts the result

    You should create 3 variables (sum, product, difference) to help keep your code neat and clean!

  5. Test your methods by invoking them in your script and running your script from the terminal.

results matching ""

    No results matching ""