Skip to content

Instantly share code, notes, and snippets.

@nathantross
Forked from aikalima/gist:8465382
Last active January 3, 2016 15:19
Show Gist options
  • Select an option

  • Save nathantross/8481997 to your computer and use it in GitHub Desktop.

Select an option

Save nathantross/8481997 to your computer and use it in GitHub Desktop.

#Debugging & Testing

Find the errors in the following

1.)*

My script is loading fine, but separate style sheets aren't working

<!DOCTYPE html>

<html>

	<head>
		<link rel="sytlesheet" type="text/css" href="/style/style.css">
	</head>

2.)*

Why is my form not working?

<form action="get" method="/">
	<input type="text" name="my_name">
	<button>Submit</button>
</form>

Added _


3.) *

My double route isn't working! Why isn't the route working?

…
get "/double/:my_number" do
	
  input = params[:my_number]
  @double = 2*input.to_i
 
 erb :show
  
end

.to_i

What does get "/double/2" return?

4


4.) *

My greet route isn't working! What should I change?

app.rb

get "/greet/:name" do
	
	@submitted_name = params[:name]
	
	erb :show
end

@

show.erb

<div>
	 Hello <%= @submitted_name %>!
</div>

When I go to /greet/world expecting Hello World!, but I get the following error:

 NameError at `/greet/world`
undefined local variable or method `id' for
 #<Sinatra::Application:0x007f892315d160>
 
 BACKTRACE
 ____________________________________________
 2.		<%= submitted_name %>

@

5.)*

What do you think of my controller? I don't even need a view. Why shouldn't I put all this in my controller?

get "/" do
	pageTitle = "myApp!"
	"<!DOCTYPE html>
	<html>
		<head>
				<title>#{pagetitle}</title>
		</head>
		<body>
				<div>
					Hello there!
				</div>
		</body>
	</html>"
end

RESTful Seperation of Concerns Hard to update, ugly, long document


6.)*

Look at my view! This works, but why should I be doing things this way?

app.rb

get '/person/:name` do
	erb :show
end		

show.erb

	<div>
		<% person = params[:name] %>
	
		Hello <%= person %>
	</div>

Or separate the content that's page specific onto pages. Seperation of Concerns


7.)*

Revise the method so that this test will pass

describe "square method" do
	it "should square each element in the array" do
		my_array = [ 1, 2, 3, 4, 5]
		square(my_array).should == [ 1, 4, 9, 16, 25]
	end
end

my_array = [ 1, 2, 3, 4, 5]

def square(my_array)
	array.map { |element| element**2 }
end

map


8.)/

Determine the result of the method call

def mystery_method(array)
	array.inject(2)	{ |acc, num| acc*num }
end

# Determine the results of the following command
puts mystery_method([1,2,3,4])

123*4 48


9.)*

Find the 2 errors in this css file

div {
	color: red;
	float: left;
	}

10.)/

a. How to reference the Director of the movie Jaws.

?tesh_has[Search].index[0]

test_hash[

select_jaws = test_hash['Search'].select {|movie| movie[:Title] == "Jaws"}.map { |info| info[:Director] } select_jaws ==> Steven Spielbert

or

test_hash['Search'].find {|movie| movie[:Title] == "Jaws"}[:Director]

b. How to reference the Year of the movie Die Hard.

test_hash = {
	"Search" => [{
		Title: "Jaws",
		Data: {Year: 1975, Rating: 'PG', Runtime: '124 min'},
		Director: "Steven Spielberg"},
		{
		Title: "Die Hard",
		Data: {Year: 1988, Rating: 'R', Runtime: '131 min'},
		Director: "John McTiernan"}]}	

i = [:Year]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment