Skip to content

Instantly share code, notes, and snippets.

@sjgjohnston
Last active December 24, 2015 17:09
Show Gist options
  • Save sjgjohnston/6833571 to your computer and use it in GitHub Desktop.
Save sjgjohnston/6833571 to your computer and use it in GitHub Desktop.
debug_1_sjohnston.md

Debugging (Use The Duck… )

Find the errors in the following

1.)

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

<head>
    <script src="/script/script.js"></script>
    <link src="sytlesheet" type="text/css" href="/style/style.css">
</head>


#### ANSWER:

The link element is referencing src="stylesheet", where is should use the syntax: rel="stylesheet" if you want the stylesheet to be referenced/used properly.

2.)

My scripts are loading, but they aren't working! How should I fix them? What's wrong?

<script type="text/script" src="/script/script_1.js"></script> <script type="text/script" src="/script/script_2.js"></script>
#### ANSWER:

Here the type="text/script" should be: type="text/javascript" or absent. The type attribute can contain one of the following: text/javascript, text/ecmascript, application/javascript, and application/ecmascript.

3.)

If the CLICK ME button is clicked twice what does the console display?

html (the error isn't here) … CLICK ME …

JS … var count = 0; function clickAction(){ count += 1; console.log("hello "+ count) }

document.getElementById("someId").onclick = clickAction() …

#### ANSWER:

It displays: hello 1 hello 2 when you run the 'document.getElementById("someId").onclick = clickAction()' twice in Javascript

When you run the page and look at the console it displays: hello 1 Uncaught TypeError: Cannot set property 'onclick' of null

4.)

What's the error? function countPlusTenSquared(){ var increment = 10; var count += increment; return count*count; }

#### ANSWER:

You can't used +=, you need to define it with the long form, i.e. var count = count + increment;

5.)

Why is my form not working?

#### Answer:

Because you have not defined what the method type is, i.e. GET, POST, PUT, DELETE etc.... You have told your form to use an action="get", but that action is probably the method you meant to state, and where you have that route defined you should have a method definition there too...

6.)

My double route isn't working! Why isn't the route working? … get "/double/:my_number" do

input = params[:my_number] @double = 2*input

erb :show

end What does get "/double/2" return?

#### Answer:

params should be referenced as :params ?

What does get "/double/2" return? TypeError at /double/2 String can't be coerced into Fixnum

Also, the route name should probably be bound by single quotes for consistency of style.

7.)

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

Hello <%= submitted_name %>!
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 #

BACKTRACE


  1. <%= submitted_name %>
    

8.)

Is this RESTful?

I have a site http://somelist.com that stores peoples names in a list.

I made the following routes GET '/name/new' # for showing a new form

GET '/name/create' # for submiting a 'new' name form, # and creating

GET '/name/:id/delete' # for submitting a deleting for a name

GET '/name/:id/edit # for showing a new edit form

GET '/name/:id/edit/post' # for submitting an edit # from a form Please give a little explanation.

9.)

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!" " <title>#{pagetitle}</title>

Hello there!
" end

10.)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment