Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chriskchew/d34d824576555a2fc4d4a880286f1916 to your computer and use it in GitHub Desktop.
Save chriskchew/d34d824576555a2fc4d4a880286f1916 to your computer and use it in GitHub Desktop.
// 1. What does this function do? How would you call it?
function doWork(a) {
return function(b) {
return a + b;
}
}
// 2. What does this function do? How would you call it?
function doWork(id) {
return fetch(`http://somewhere.com/book/${id}`)
.then(response => {
return response.json();
})
.then(json => {
return json.author;
});
}
// 3. What does this function do? If you were asked to provide comments on this code (like in a code review),
// what would you comment on?
function setupClickHandlers() {
var x = document.querySelectorAll('.list-item');
for (var i = 0; i < x.length; i++){
var x1 = x[i];
x1.onclick = function(evt) {
var ET = evt.target;
if(ET.className.indexOf('active') != -1) {
ET.className = 'list-item';
} else {
ET.className = 'list-item active';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment