Skip to content

Instantly share code, notes, and snippets.

# 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}
]
#################################
# Automating repetition
#################################
# .times is a way to loop in Ruby.
# This is how you print "howdy" five times:
# 5.times do
# puts "howdy"
# end
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
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"
first = "Meryl"
last = "Charleston"
birthday = "June 9"
puts "#{first} #{last} was born on #{birthday}."
first = "Rachel"
last = "Conley"
birthday = "October 31"
@raghubetina
raghubetina / gist:4162076
Created November 28, 2012 15:45
JavaScript Example
<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>
@raghubetina
raghubetina / gist:4161422
Created November 28, 2012 13:46
Client-side Scripting
<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>
@raghubetina
raghubetina / euler_p1.rb
Created July 7, 2012 19:16
Project Euler Problem 1
# 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"