Skip to content

Instantly share code, notes, and snippets.

@iamwinnie
iamwinnie / cat.rb
Created March 31, 2019 00:17
3.5 object oriented programming II
class Pet #define Pet
attr_reader :color, :breed # attribute reader method
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end #end initialize method
@iamwinnie
iamwinnie / cat.rb
Created March 28, 2019 21:48
3.4 object-oriented programming I
class Cat
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
@iamwinnie
iamwinnie / fav_foods.rb
Created March 28, 2019 20:02
3.3 data structures
def fav_foods
food_array = []
3.times do
puts "Name a favorite food."
food_array << gets.chomp
end
p food_array
puts "Your favorite foods are #{food_array.join(", ")}."
food_array.each { |food| puts "I like #{food} too!"}
end
@iamwinnie
iamwinnie / program2.rb
Last active March 28, 2019 05:04
3.2 Control flow in ruby
if true
puts "this is true"
else
puts "this is false"
end
if (5+5==10)
puts "this is true"
else
@iamwinnie
iamwinnie / program.rb
Created March 28, 2019 02:52
3.1 Meet Ruby
my_name = "Winnie"
puts "hello"
def sayhello(name)
puts "hello" + " " + name
end
sayhello(my_name)
@iamwinnie
iamwinnie / index.html
Created March 27, 2019 23:21
2.12: Interactive website
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Winnie</title>
<!-- Bootstrap core CSS -->
@iamwinnie
iamwinnie / scripts.js
Created March 27, 2019 22:02
2.11 JavaScript & APIs
$(document).ready(function() {
$('.message-box').css('background', '#D5FDD5');
$('#button').on('click', function() {
var comment = $('.message-box').val();
console.log(comment);
if (comment === "") {
$('.message-box').css('border', '2px solid red');
} else {
$('#invisible-comment').html('We received your message:' + ' ' + comment);
@iamwinnie
iamwinnie / scripts.js
Created March 27, 2019 03:21
2.10 object literals
$(document).ready(function() {
$('.message-box').css('background', '#D5FDD5');
$('#button').on('click', function() {
var comment = $('.message-box').val();
console.log(comment);
if (comment === "") {
$('.message-box').css('border', '2px solid red');
} else {
@iamwinnie
iamwinnie / scripts.js
Created February 14, 2019 02:42
2.7 intro to jquery
$(document).ready(function() {
$('.message-box').css('background', '#D5FDD5');
$('#button').on('click', function() {
var comment = $('.message-box').val();
console.log(comment);
$('#invisible-comment').html('We received your message:' + ' ' + comment);
$('.message-box').hide();
return false;
});
@iamwinnie
iamwinnie / index.html
Created December 27, 2018 20:09
2.1 semantic HTML & footer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Winnie</title>
<!-- Bootstrap core CSS -->