// how could you rewrite the following to make it shorter? if (foo) { bar.doSomething(el); } else { bar.doSomethingElse(el); } // how could this code be rewritten in order to remove the if? if (foo) { bar.doSomething(); } // given the following code, and assuming that each created 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() }; // how could you improve the following code? $(document).ready(function() { $('.foo #bar').css('color', 'red'); $('.foo #bar').css('border', '1px solid blue'); $('.foo #bar').text('new text!'); $('.foo #bar').removeClass('btn'); $('.foo #bar').removeClass('primary'); $('.foo #bar').click(function() { $(this).attr('title', 'new title'); $(this).width('100px'); }); $('.foo #bar').click(); }); // 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>'); } /* According to the following HTML: <div id="button">button</div> <button id="alert">Click me!</button> How to improve and make the code below work? */ $("#button").click(function(){ $("body").append('<button class="btn" id="alert">Click now!</button>'); }); $("#alert").click(function(){ alert('Alert clicked'); });