Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
kareemgrant / america.rb
Last active August 29, 2015 14:18
BE101 Session 1 Homework Answers
def america_phrase(phrase)
"#{phrase}; Only in America!"
end
puts "Enter a phrase"
input = gets.chomp
puts america_phrase(input)

Goals

  1. Solidify your understanding of classes and objects

Assignment

  1. Create a program that takes a word and provides a Scrabble score associated with that word. A lookup hash that associates letters with scores can be found here

Bonus scenarios such as double word or triple letter scores should not be taken into account

require 'geolocater'
record = Geolocater.geolocate_ip("64.119.207.255")
puts record

Goals

  1. Solidify your understanding of basic Ruby programming concepts

  2. Be prepared for slightly more advanced material on Thursday

Assignment

  1. Create the following functions:
  • Create a function that takes a string and adds the phrase "Only in America!" to the end of it

Homework

Goals

  1. Continue to solidify your understanding of basic Ruby programming concepts

  2. Be prepared to learn about Ruby libraries on Tuesday

Assignment

  1. Create a program to analyze a large block of text and report back on the frequency of each word in the text.
{
"A"=>1, "B"=>3, "C"=>3, "D"=>2,
"E"=>1, "F"=>4, "G"=>2, "H"=>4,
"I"=>1, "J"=>8, "K"=>5, "L"=>1,
"M"=>3, "N"=>1, "O"=>1, "P"=>3,
"Q"=>10, "R"=>1, "S"=>1, "T"=>1,
"U"=>1, "V"=>4, "W"=>4, "X"=>8,
"Y"=>4, "Z"=>10
}
<!DOCTYPE html>
<html>
<head>
<title>Railsapp4</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find_by_id(params[:id])
end
def edit
<h1>Posts for one user:</h1>
<% @posts.each do |post| %>
<%= post.title %>
<% end %>