Skip to content

Instantly share code, notes, and snippets.

@dthtien
Forked from schneems/gist:3118875
Last active May 11, 2017 08:22
Show Gist options
  • Save dthtien/a504d627465ce66f73b1b55bbd1d2255 to your computer and use it in GitHub Desktop.
Save dthtien/a504d627465ce66f73b1b55bbd1d2255 to your computer and use it in GitHub Desktop.
Week 6 Quiz
## 1) Instance or class method?
A) User.where(:name => 'rich')
- class method
B) @user.favorite_movie
- instance method
C) [1,2,3,4].map {|x| x + 1 }
- instance method
D) Hash.new
- class method
E) "richard".upcase
instance method
## 2) Which is an instance method and which is a class method?
class Product
def self.highest_rated
# ...class method
end
def rating
# ...instance method
end
end
## 3) Here is an example HTML and some jQuery selectors, give me the contents of the HTML for the jQuery selector.
<p>
Hello there
</p>
<ul>
<li id='thebest'>Ruby</li>
<li class='thebest'>javascript</li>
<li class='thebest maybe'>python</li>
</ul>
Example:
$('p')
Returns HTML with the contents
"Hello there"
A) $('#thebest'): ruby
B) $('.maybe') python
C) $('.thebest'):[javascrip, python]
## 3) In the example above how would you describe the relationship between `ul` & `li`? What about between `p` & `ul`?
ul is parent of li
li is child of ul
p and ul are sibling
## 4) What folder do you put assets go in a Rails project?
app/asset
## 5) Describe what a callback function is, explain why you would want to use one? What is the alternative to a callback function?
Callback functions are used in code when we don't want to wait for an event or we don't want to use polling to constantly check to see if an event has happened. We use callbacks so we can effectively use our code's time, and we don't have to block on waiting for events.
One alternative to a callback function is polling ("are we there yet?").
## 6) Give me one example of a DOM event.
on('cl',function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment