Git Product home page Git Product logo

wdi7-quiz3's Introduction

Quiz #3

Instructions

  1. Fork this repo
  2. Clone your fork
  3. Fill in your answers by writing in the appropriate area, or placing an 'x' in the square brackets (for multiple-choice questions).
  4. Add/Commit/Push your changes to Github.
  5. Open a pull request.

Note: only place your answer between backticks. Don't modify the backticks, or the language specifier after them.

Ruby Basics & Enumerables (meets Beauty and the Beast)

Question 1

Define a method called offerRose, which should take one argument named person.

When called, the method should puts, "Would you take this rose and help out an old beggar, X?", where X is the person passed into the method.

Demonstrate calling the method with an argument of "young prince".

Write your code here:

def offerRose
  puts "Would you take this rose and help out an old beggar, #{person}?"
end

offerRose("young prince")

Question 2

Assume the following hash:

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

Using Ruby, remove Belle from the town residents, and add her to the list of guests in the castle.

Write your code here:

town[:residents] = ["Maurice", "Gaston"]
town[:castle][:guests] = "Belle"

Question 3

Assume you have an array of strings representing friend's names:

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

Using .each AND string interpolation, produce output (using puts) like so:

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

Write your code here:

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

SQL, Databases, and ActiveRecord (meets Aladdin)

Question 4

Describe what an ERD is, and why we create them for applications. Also give an example what the attributes and relationships might be for the following entities (no need to draw an ERD):

  • Genie
  • Lamp
  • Person
  • Pet

Your answer:

An ERD is a graphic representation of relationships between items. Genie - Lamp = 1:1. Person - Pet = many:many (pet could have many owners, ie mom, dad, kids, and a person could have many pets).

Question 5

Describe what a schema is, and how we represent a one-to-many relationship in a SQL database. If you need an example, you can use: people and wishes (one-to-many).

Your answer:

A schema contains the data that goes into a database.

Question 6

Assume:

  1. Your database two working tables, genies and lamps.
  2. You have a working connection to the database for ActiveRecord.
  3. You have active record models defined for Genie and Lamp, and the relationships between the two are set up in Active Record.
  1. Lamps have one property, wishes_remaining, and genies have one property, name.

Write code to do the following:

  1. Create a lamp with 3 wishes remaining and a genie named 'Genie'
  2. Create a relationship between 'Genie' and the lamp.
  3. Update the lamp so it only has one wish left.
  • Oh no... Jafar has Aladdin! Thankfully he's wished to become a genie himself!
  1. Create a new Genie named 'Jafar' and put him in a new lamp with 3 wishes left.
  2. Free the good Genie by setting his lamp to nil

Write your code here:

# code here

Sinatra / REST (meets Mulan)

Question 7

The Chinese Emperor needs an application to help him manage his warriors.

Describe to him what a RESTful route is, and list what the seven RESTful routes would look like for such an application.

Your description:

Replace this with your answer

Your routes:

The ancestors have provided an example of one route; you do the other six!

GET '/warriors/:id'

GET '/warriors/:id/edit'

GET '/warriors/new'

POST '/warriors'

DELETE 'warriors/:id'

PUT '/warriors/:id'

  • This is the show route, which finds a warrior by ID, and displays information about that warrior.

Replace this with your answer


### Question 8

Assume:
* Warrior is an ActiveRecord model, with a 'name' attribute.
* You have a Sinatra `app.rb` (or similar file), that defines the following
route:

```ruby
get '/warriors' do
  @warriors = Warrior.all
  erb :"warriors/index"
end

Write what an example ERB file (aka view) might look like to list all the warriors:

Write your code here (NOTE: syntax highlighting doesn't work for ERB in markdown files, so ignore the colors!):

<ul>
  <% @warriors.each do |warrior| %>
    <li><%= warrior.name %></li>
  <% end %>
</ul>

wdi7-quiz3's People

Contributors

adambray avatar ebirving avatar tkentor avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.