Created
September 16, 2010 23:41
-
-
Save jimbojw/583389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
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
Yeah, I guess it's hard to test a "pure" question. The question you just poses also tests object literal and array literal notation. I still run across people that use new Array().
I don't think the order of operations bug is too subtle - I would expect any developer that's familiar with C-style syntax to pick up on it.
I think it's a pretty good question! Maybe the right approach is to start with questions that test just one thing (if that's even possible), and then graduate to questions that test multiple concepts. The trouble you run into there (if it can even be considered trouble) is people learning from early questions language semantics that help them later on. Then again, if someone has only ever seen new Array(), and learns from question #1 that [] does the same and is then able to incorporate that into their thinking to solve problems #2 and #3, that may be enough of a positive to warrant the hire.
Again, it depends on what you're hiring for - do you want somebody who's already a rock star, or someone who has the potential to become one. If I had my druthers, I'd only hire the former - let my competitors train recent college grads, then encourage them to trade up to my company. :)