-
-
Save benhodgson/578901 to your computer and use it in GitHub Desktop.
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: assuming inputElement and otherElement are defined and are DOM nodes, how | |
| // could you rewrite the following to make it shorter? | |
| if (foo) { | |
| bar.doSomething(el); | |
| } else { | |
| bar.doSomethingElse(el); | |
| } | |
| bar[foo ? 'doSomething' : 'doSomethingElse'](el); | |
| // 2: what is the faulty logic in the following code? | |
| var foo = 'hello'; | |
| (function() { | |
| var foo = foo || 'world'; | |
| console.log(foo); | |
| })(); | |
| // 3: given the following code, how would you override the value of the bar | |
| // property for the variable foo without affecting the value of the bar | |
| // property for the variable bim? what if you did want to affect the value of | |
| // the bar property for both foo and bim? | |
| var Thinger = function() { | |
| return this; | |
| } | |
| Thinger.prototype = { | |
| bar : 'baz' | |
| }; | |
| var foo = new Thinger(), | |
| bim = new Thinger(); | |
| // 4: given the following code, and assuming that each defined object has a | |
| // 'destroy' method, how would you destroy all of the objects contained in the | |
| // myObjects object? | |
| var myObjects = { | |
| thinger : new myApp.Thinger(), | |
| gizmo : new myApp.Gizmo(), | |
| widget : new myApp.Widget() | |
| }; | |
| // 5: given the following array, create an array that contains the contents of | |
| // each array item repeated three times, with a space between each item. so, | |
| // for example, if an array item is 'foo' then the new array should contain an | |
| // array item 'foo foo foo'. (you can assume jQuery, dojo, or underscore is | |
| // available) | |
| var myArray = [ 'foo', 'bar', 'baz' ]; | |
| // 6: what potential issues do you see with the following code? how would you fix it? | |
| $(document).ready(function() { | |
| $('.foo #bar').css('color', 'red'); | |
| $('.foo #bar').css('border', '1px solid blue'); | |
| $('.foo #bar').text('new text!'); | |
| $('.foo #bar').click(function() { | |
| $(this).attr('title', 'new title'); | |
| $(this).width('100px'); | |
| }); | |
| $('.foo #bar').click(); | |
| }); | |
| // 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; | |
| } | |
| }); | |
| if (foo) { | |
| // run this important code | |
| } | |
| })(); | |
| // 8: how could you rewrite the following code to make it shorter? | |
| $('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.baz a').attr('title', 'i am baz'); | |
| $('li.bop a').attr('title', 'i am bop'); | |
| // 9: how would you improve the following code? | |
| for (i = 0; i <= 5; i++) { | |
| $('#thinger').append('<p><span class="thinger">i am thinger ' + i + '</span></p>'); | |
| $('#gizmo').append('<p><span class="gizmo">i am thinger ' + i + '</span></p>'); | |
| } | |
| // 10: a user enters their desired tip into a text box; the baseTotal, tax, | |
| // and fee values are provided by the application. what are the potential | |
| // issues with the following function for calculating the total? | |
| function calculateTotal(baseTotal, tip, tax, fee) { | |
| return baseTotal + tip + tax + fee; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment