Skip to content

Instantly share code, notes, and snippets.

class Pet
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
class Cat
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
def fav_foods
food_array = []
3.times do
puts "Name a favorite food."
food_array << gets.chomp
end
p food_array
puts "You favorite foods are #{food_array.join(", ")}"
food_array.each do |food|
puts "I like #{food} too"
# number = 0
# while (number <= 10) do
# p "the number is now #{number}"
# number += 1
# end
(0..10).each do |n|
p "the new number is #{n}"
end
def choose
puts "Do you like programming? Yes, no or maybe please."
choice = gets.chomp
case choice.downcase
when "yes"
puts "That\'s Awesome!"
when "no"
puts "That\'s to bad, time to quit!"
when "maybe"
puts "That\'s ok, it will get better."
#if (5+5=10)
if true
puts "this is true"
else
puts "this is false"
end
my_name = "Batman"
def greeting(name)
p "hello" + " " + name
end
greeting("Craig")
greeting(my_name)
def greeting
puts "Enter your name here:"
window.onload = function() {
var current,
screen,
output,
limit,
zero,
period,
operator;
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<link rel="stylesheet" href="css/style.css">
</head>
body {
background:#fff;
}
#background {
width:300px;
height:400px;
background:gray;
margin:50px auto;
}