This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My solution: | |
# First, a helper method: | |
def is_a_multiple_of?(factor, candidate) | |
return candidate % factor == 0 | |
end | |
sum = 0 # I read this as: | |
1.upto(999) do |number| # "From 1 upto 999, for each number," | |
if is_a_multiple_of?(3, number) # "If the number is a multiple of 3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Chicago</h1> | |
<h1>San Francisco</h1> | |
<h1>New York</h1> | |
<h1>Boston</h1> | |
<a href="http://www.google.com" id="button">Abracadabra!</a> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Chicago</h1> | |
<h1>San Francisco</h1> | |
<h1>New York</h1> | |
<h1>Boston</h1> | |
<a href="http://www.google.com" id="button">Abracadabra!</a> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first = "Meryl" | |
last = "Charleston" | |
birthday = "June 9" | |
puts "#{first} #{last} was born on #{birthday}." | |
first = "Rachel" | |
last = "Conley" | |
birthday = "October 31" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'json' | |
require './student.rb' | |
s1 = Student.new | |
s1.name = "Raghu Betina" | |
s1.photo_url = "https://graph.facebook.com/rbetina/picture" | |
s1.section = "am" | |
s1.twitter = "rbetina717" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student | |
attr_accessor "name" | |
attr_accessor "photo_url" | |
attr_accessor "section" | |
attr_accessor "twitter" | |
def introduce | |
return "#{@name} (@#{@twitter}) is in the Web Dev #{@section.upcase} class." | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################# | |
# Automating repetition | |
################################# | |
# .times is a way to loop in Ruby. | |
# This is how you print "howdy" five times: | |
# 5.times do | |
# puts "howdy" | |
# end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hard Challenge: Based on the data stored in the shopping_cart, sales_tax, and params variables below, write code that prints out the customer's total, including estimated sales tax, based on the shipping address they entered. Your code should work even if the values of the data change. | |
# Your output should look like this: | |
# Your total with tax is $4455.54. | |
shopping_cart = [ | |
{'name' => "iPad 2", 'price' => 499, 'quantity' => 2}, | |
{'name' => "iMac 27", 'price' => 1699, 'quantity' => 1}, | |
{'name' => "MacBook Air 13", 'price' => 1299, 'quantity' => 1} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5.times do |i| for (var i = 0; i < 5; i++) { | |
puts "howdy #{i}" alert("howdy " + i.toString()); | |
end }; | |
(10..20).step(2) do |i| for (var i = 10; i <= 20; i = i + 2) { | |
puts "howdy #{i}" alert("howdy " + i.toString()); | |
end }; | |
a = ["apple", "orange", "banana"] var a = ["apple", "orange", "banana"]; | |
a.each do |fruit| for (var i = 0; i < a.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'json' | |
your_access_token = "put your access token from the Graph API Explorer here" | |
url = "https://graph.facebook.com/me/home?fields=from,picture,link,source,name,description,type&access_token=#{your_access_token}" | |
result = JSON.parse(open(url).read) | |
posts = result["data"] |
OlderNewer