This file contains hidden or 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
// 7: what issues do you see with the following code? how would you fix it? | |
(function() { | |
var foo; | |
dojo.xhrGet({ | |
url : 'foo.php', | |
load : function(resp) { | |
foo = resp.foo; | |
} | |
}); |
This file contains hidden or 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
// 8: how could you rewrite the following code to make it shorter? | |
(function(d, $){ | |
$('li.foo a').attr('title', 'i am foo'); | |
$('li.bar a').attr('title', 'i am bar'); | |
$('li.baz a').attr('title', 'i am baz'); | |
$('li.bop a').attr('title', 'i am bop'); | |
})(dojo, dojo.query); |
This file contains hidden or 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
// 9: how would you improve the following code? | |
for (i = 0; i <= 100; i++) { | |
$('#thinger').append('<p><span class="thinger">i am thinger ' + i + '</span></p>'); | |
$('#gizmo').append('<p><span class="gizmo">i am gizmo ' + i + '</span></p>'); | |
} |
This file contains hidden or 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
// 10: a user enters their desired tip into a text box; the baseTotal, tax, | |
// and fee values are provided by the application. what are some potential | |
// issues with the following function for calculating the total? | |
function calculateTotal(baseTotal, tip, tax, fee) { | |
return baseTotal + tip + tax + fee; | |
} |
This file contains hidden or 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
// 11: given the following data structure, write code that returns an array | |
// containing the name of each item, followed by a comma-separated list of | |
// the item's extras, if it has any. e.g. | |
// | |
// [ "Salad (Chicken, Steak, Shrimp)", ... ] | |
// | |
// (you can assume the library of your choice is available) | |
var menuItems = [ | |
{ | |
id : 1, |
This file contains hidden or 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
// BONUS: write code such that the following alerts "Hello World" | |
say('Hello')('World'); |
This file contains hidden or 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
// BONUS: what is the faulty logic in the following code? how would you fix it? | |
var date = new Date(), | |
day = date.getDate(), | |
month = date.getMonth(), | |
dates = []; | |
for (var i = 0; i <= 5; i++) { | |
dates.push(month + '/' + (day + i)); | |
} |
This file contains hidden or 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
/* | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. |
This file contains hidden or 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
// 1: how could you rewrite the following to make it shorter? | |
if (foo) { | |
bar.doSomething(el); | |
} else { | |
bar.doSomethingElse(el); | |
} |
This file contains hidden or 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
bar[foo ? 'doSomething' : 'doSomethingElse'](el); | |
// OR | |
bar['doSomething' + (foo ? '' : 'Else')](el); |