Skip to content

Instantly share code, notes, and snippets.

@jimbojw
Created September 16, 2010 23:41
Show Gist options
  • Save jimbojw/583389 to your computer and use it in GitHub Desktop.
Save jimbojw/583389 to your computer and use it in GitHub Desktop.
// For each of the following code fragments:
// a. what does the code do?
// b. what did the author intend for it to do?
// c. how would you fix it?
// 1. list of links
var p = document.createElement('p');
for (var i=0; i<10; i++) {
var a = document.createElement('a');
a.innerHTML = "link " + i;
a.onclick = function() {
alert("you clicked link " + i);
return false;
};
p.appendChild(a);
}
document.body.appendChild(p);
// 2. method callback
var bob = {
firstname: "Bob",
greet: function() {
alert("Hi, I'm " + this.firstname);
}
}
window.onload = bob.greet;
@xavi-
Copy link

xavi- commented Oct 18, 2010

Haha, I like the idea of trading to a company.

I'm going to fork the gist and make the changes we talked about: add the browser compatibility note and add the easy first question.

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