Skip to content

Instantly share code, notes, and snippets.

@rserur
rserur / guess_the_number.js
Created June 19, 2014 13:45
LA: Guess the Number w/ too high/low alerts
var num = Math.floor((Math.random() * 100) + 1);
var name = prompt("What's your name?");
var guess = null;
while (guess != num) {
var guess = prompt(name + ", enter a guess, between 1 and 100 (or enter Q to quit).");
if (guess > num) {
alert("Too high!");
@rserur
rserur / minefield.rb
Last active August 29, 2015 14:02
LA Minesweeper
require 'pry'
class Minefield
attr_reader :row_count, :column_count
def initialize(row_count, column_count, mine_count)
@column_count = column_count
@row_count = row_count
@empty_cells = (column_count * row_count) - mine_count
@clear_count = 0
@rserur
rserur / blackjack.rb
Created June 3, 2014 19:34
LA Blackjack
class Deck
def initialize
@collection = []
# Fill deck with cards, SUITS * VALUES
Card::SUITS.each do |suit|
Card::VALUES.each do |value|
@collection << Card.new(value, suit)
@rserur
rserur / mortgage.rb
Created June 2, 2014 20:04
Mortgage Calculator
class Mortgage
def initialize(home_value, down_payment_percentage, apr, duration_in_years)
@home_value = home_value
@down_payment_percentage = down_payment_percentage
@apr = apr
@duration_in_years = duration_in_years
end
def down_payment
@down_payment = @home_value * @down_payment_percentage
@rserur
rserur / ink_left.rb
Created June 2, 2014 18:53
Ink Left?
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end
@rserur
rserur / dryerase.rb
Created June 2, 2014 18:51
Dry Erase Marker
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end
@rserur
rserur / card_getters.rb
Created June 2, 2014 18:31
Card Getters
class Card
def initialize(rank, suit)
@suit = suit
@rank = rank
end
def suit
@suit
end
@rserur
rserur / getters.rb
Created June 2, 2014 18:28
Getters
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end
@rserur
rserur / constructors.rb
Created June 2, 2014 18:20
Constructors
class Television
def initialize(screen_size,type,brand)
@screen_size = screen_size
@type = type
@brand = brand
end
end
@rserur
rserur / rand_card.rb
Created June 2, 2014 15:27
LA Random Card Generator
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
@rank = ['1','2','3','4','5','6','7','8','9'].sample
else