-
-
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; |
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. :)
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.
Currently, this gist checks if the interviewee can read, debug, and fix code. With that in mind, I feel the fizzbuzz question should look something like this:
This question tests if the candidate understands object/array literals,
for
loops, and function calls. Though, I'm a bit concerned that it's too basic and that the bugs are too subtle (especially the missing parens on line 5). Thoughts?