Print the text "Hello, world!"
puts "Hello, World"
What data type did you print?
string
Print the result of the expression 2 + 2
p 2+2
What data type did you print?
integer
Assign the result of the expression 2 + 2 to a variable named result
result = 2 + 2
What data type is the value of result?
integer
Write a method which takes two parameters and adds them, returning the result.
def addTwo(a,b)
p a + b
end
On what datatypes will the function you wrote work correctly? Incorrectly?
It will work correctly with strings, but with integers it will only concatenate the numbers, not add them.
What is the difference between testing for equality and assigning a value to a variable? (Show an example of both)
a == 3 tests for equality
a = 3 assigns value to a
What data type is [1, 2, 3, 4, 5]?
an array
Iterate through the above data structure, printing each number multiplied by two.
arr = [1, 2, 3, 4, 5]
for arr.each do |a|
p a * 2
end
Iterate through the above data structure, printing "I am the [n]th element", replacing 'n' with each element's index.
arr = [1, 2, 3, 4, 5]
for arr.each do |i|
p "I am the #{arr[i]}th element."
end
What data type is {cats: 3, dogs: 2, fish: 13}?
a hash
What is the data type and role of cats in the above structure?
a key of a key/value pair
What are the roles of the integers in the above structure?
they're values
Iterate through the above data structure, printing "Kyle has [n] [thing]s", replacing 'n' and 'thing' with the appropriate values.
max_animal that accepts a data structure like the above as a parameter, and returns which type of animal Kyle has the most of.Write a class called Man with an instance method move, which prints walk, and an attribute name with a reader and writer method.
class Man
attr_accessible :name
def initialize(move)
@move = move
@name = name
end
def walk
p name.walk
end
end
name = Man.new
Write a subclass of Man called Superman, whose move method prints fly
class Superman < Man
def move
end
end
Add a class method to your Superman class called is_superhero? which returns true.
name attribute to Superman? If not, why?Does Ruby have methods, functions, or both?
ruby has methods
Whichever of the above (method/function) you decided, can it be stored in a variable?
yes
What is the name of this construct in Ruby: do |thing| thing * 2 end
loop
Print the text "Hello, world!"
console.log('Hello, world!');
Print the result of the expression 2 + 2
console.log(2 + 2)
Assign the result of the expression 2 + 2 to a local variable named result
result = 2 + 2
Write a function which takes two parameters and adds them, returning the result.
var addTwo = function(a,b){
a + b;
}
addTwo(1,2);
On what datatypes will the function you wrote work correctly? Incorrectly?
integers
What data type is [1, 2, 3, 4, 5]?
an array
Iterate through the above data structure, printing each number multiplied by two.
arr = [1, 2, 3, 4, 5]
for (var = i; i > arr.length; i++){
console.log(arr[i] * 2);
}
What data type is {cats: 3, dogs: 2, fish: 13}? (Hint: NOT the same as the Ruby answer)
In setTimeout(doStuff, 2000), what datatype should doStuff be and what do we call that datatype in this role?
do stuff is an object and in this role it's something else
What datatype is foo in var foo = function() { alert("Hello"); };?
object
Is a function a type of object?
yes
Show how you would use var Person = function(){}; to construct a Person.
What is a prototype?
a prototype is an object that stands in for something more complicated declared earlier in the program
What do I mean every time I say "In Javascript, functions are first-class values"?
they're top level,
What is the difference between an AJAX request and a typical HTTP request?
ajax requests happen on the same page, without having to refresh
What type (three letter acronym) of framework is Rails?
MVC
Define each of the three components
M = Model: where the data is gathered and stored
V = View: where Rails interacts with the browser
C = Controller: handles the transferring and placement of data
In your shell...
Make a new rails project called blog
rails new blog
In that project, make a new controller PostsController
rails g controller posts
Make a Post model
rails g model post
Make PostsController and the Post model, as well as RESTful routes, in a single step.
rails g controller posts model posts index
Run the migrations for Post
rake db:migrate
See all your app's routes
rake routes
Start the web server
rails s
In general...
What is the name of the (default) superclass of all of our generated controllers?
Base
What do we call controller instance methods that respond to web requests?
ajax
What, by default, would one such method (say, show) do if I leave its method body empty?
display the result of a show request
What kind of template is application.html.erb?
view
What kind of template is posts/_form.html.erb?
form partial
In an ERB template, with a @post var available, how would I render a link to that post's show page?
<%= link_to "That one", @post_path %>
What relationships would you define in your models if a user can have multiple posts?
blog :has_many posts
What field would you need to add to post?
post :belongs_to blog
What relationships would you define in your models if a post could have multiple categories, and a category could belong to multiple posts? What tables would you need to add?
join table
In the Rails console...
How many Posts exist in the database?
Post.all
How many Posts by user with id 1? (assuming I've properly associated a User model with the Post model)
Post.all(1)
Find the first post
Post.first
Destroy the last post
Post.delete.last
Destroy all posts by user with id 5.
Post.delete.where('userId' = 1)
Create a post with user id 1, title "My Post", and body "This is the body of my first post"
Select an element with id foo
$('#foo').select
Select all elements with class bar
$('.bar').select.all
Select all the <div>s on the page.
$('div').select
Create a new div with id baz.
$('div').create('#baz')
Append that newly created div to a div with id foo
$('#baz).appendTo('#foo')
Remove all input elements from the page.
$('input').delete
Remove all the children of the div with id foo
$('#foo').children.delete
Hide all divs with class oops
$('.oops').hide
Hide all the children of the div with id foo
$('.foo').children.hide
Perform an AJAX GET request to /thingList.json, iterating through the returned result set and logging each item to the console.
i'd have to look at my notes to get this (of which i have many FTR)
Explain how APIs work. In detail.
Definition
an API is a protocol to gather information from a third party website
How you interact with them
with ajax requests
Why/when you need to use them
when you want to use data that someone else has compiled
When you might build one yourself
If a data source does not currently have a properly functioning API or one at all.
What is the purpose of yield? (Ruby) Show an example.
yield brings in info from other pages in your project
Explain how http works in detail.
It sends a message to the server to look for a given URL, then gathers that data back to the server and displays the HTML files in the browser
Write a method that appends the words “in Ruby” to any English sentence, in Ruby.
puts "Type a sentence:"
sent = gets.chomp
puts sent + " in Ruby."
Write a method that converts x amount of dollars into change and specify how much of each coin will you have. E.g. convert $2.65 and return the amount of quarters, dimes, nickels, and pennies.
* Use a regular expression to extract the dollars and cents from the string
* You may use <http://rubular.com>
In Javascript, what's the difference between null and undefined?
Null mean that there is nothing there, that there is nothing to equate to, undefined means that you haven't yet set the equation's value.
When would you use a CSS float?
When you want elements to line up horizontally.
What is the "Box Model" in CSS? Which CSS properties are a part of it?
A box model are the elements that surround every CSS element. The consist of the element, padding, border and margin.