Skip to content

epoch/checkpoint2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  1. fork this repo
  2. clone your repo to your computer
  3. make a new directory with your name
  4. put your answers in this directory
  5. make a commit for every question
  6. make a pull request before time is up!!!

Question 1

Define a method called offer_rose, which should take one argument named person (String). When called the method should print to the terminal: "Would you take this rose, person, in exchange for giving an old beggar woman shelter from the bitter cold?" --> def offer_rose string puts "Would you take this rose, person, in exchange for giving an old beggar woman shelter from the bitter cold?" end

offer_rose('person')

Question 2

Assume the following hash...

town = {
  residents: ["Maurice", "Belle", "Gaston"],
  castle: {
    num_rooms: 47,
    residents: ["Robby Benson"],
    guests: []
  }
}

Using Ruby...

  • Remove "Belle" from residents
  • Add "Belle" to the guests array Type your solution directly below this line:

town[:residents].delete('Belle') town[:guests] = ['Belle']

Question 3

Assume you have an array of strings representing friends' names...

friends = ["Chip Potts", "Cogsworth", "Lumière", "Mrs. Potts"]

Using a loop and string interpolation, print each string in friends to the Terminal...

"Belle is friends with Chip Potts"
"Belle is friends with Cogsworth"
"Belle is friends with Lumière"
"Belle is friends with Mrs. Potts"

friends.each do |friend| p "Belle is friends with #{friend}" end

Question 4

Assume the following array of hashes:

lost_boys = [
  {name: 'Tootles', age: 11},
  {name: 'Nibs', age: 9},
  {name: 'Slightly', age: 10},
  {name: 'Curly', age: 8},
  {name: 'The Twins', age: 9}
]

Use .each to iterate over the lost_boys array and increase each boy's age by 30 years.

lost_boys.each { |name| name[:age] += 10 }

Question 5

Assume the following array:

children = ['Wendy', 'John', 'Michael']

Use .map to iterate through the children array and add Darling to the end of their names. Assign the returned array to a variable called darling_children. Example: Wendy should become Wendy Darling in the new array.

darling_children = children.map {|name| darling_children = [] name = "#{name} Darling" }

Question 6

Define a Ruby class called Animal. Each Animal should have...

  • A name (String) attribute

  • A greet instance method

  • The ability to "get" and "set" name class Animal

    def set_name @name = get_name().chomp end

    def get_name @name = gets end

    def greets "#{@name} says hello" end

end

animal = Animal.new

Question 7

Create a new Animal instance with the name "Pumba" an assign it to a variable named pumba.

Question 8

Write a method called toonify that takes two parameters, accent and sentence.

  • If accent is the string "daffy", return a modified version of sentence with all "s" replaced with "th".
  • If the accent is "elmer", replace all "r" with "w".
  • Feel free to add your own accents as well!
  • If the accent is not recognized, just return the sentence as-is.
toonify "daffy", "so you smell like sausage"
#=> "tho you thmell like thauthage"

Call the method twice with different arguments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages