Skip to content

Instantly share code, notes, and snippets.

@benhodgson
Forked from rmurphey/screening.js
Created September 14, 2010 11:35
Show Gist options
  • Select an option

  • Save benhodgson/578901 to your computer and use it in GitHub Desktop.

Select an option

Save benhodgson/578901 to your computer and use it in GitHub Desktop.

Revisions

  1. benhodgson revised this gist Sep 14, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -166,7 +166,7 @@ for (i = 0; i <= 100; i++) {
    }

    // A: manipulating the DOM is expensive. using join('') is also more memory-
    // efficient that concatenating strings in a compund fashion
    // efficient that concatenating strings in a compound fashion

    var thingerVals = [],
    gizmoVals = [];
  2. benhodgson revised this gist Sep 14, 2010. 1 changed file with 100 additions and 5 deletions.
    105 changes: 100 additions & 5 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,24 @@
    // Hello! I am Ben Hodgson.

    // 1: how could you rewrite the following to make it shorter?
    if (foo) {
    bar.doSomething(el);
    } else {
    bar.doSomethingElse(el);
    }


    // A:
    bar[foo ? 'doSomething' : 'doSomethingElse'](el);


    // 2: what is the faulty logic in the following code?
    var foo = 'hello';
    var foo = 'hello'; // this foo...

    (function() {
    var foo = foo || 'world';
    var foo = foo || 'world'; // ...is not the same foo as this foo
    console.log(foo);
    })();

    // (you redefine it in this self–invoking function's scope)



    @@ -48,6 +51,11 @@ var myObjects = {
    widget : new myApp.Widget()
    };

    // A:
    for(var prop in myObjects) {
    myObjects[prop].destroy();
    }




    @@ -58,6 +66,21 @@ var myObjects = {
    // available)
    var myArray = [ 'foo', 'bar', 'baz' ];

    // A:
    function repeatArray(theArray, n) {
    var result = [],
    list,
    word;
    for(var i in theArray) {
    list = [],
    word = theArray[i];
    for(var j=0; j<n; j++) list.push(word);
    result.push(list.join(' '));
    }
    return result
    };

    repeatArray(myArray, 3);



    @@ -74,7 +97,16 @@ $(document).ready(function() {
    $('.foo #bar').click();
    });

    // A: chain jQuery method calls and combine CSS values into a single object

    $(document).ready(function() {
    $('.foo #bar').css({'color': 'red', 'border': '1px solid blue'});
    .text('new text!');
    .click(function() {
    $(this).attr('title', 'new title').width('100px');
    })
    .click();
    });


    // 7: what issues do you see with the following code? how would you fix it?
    @@ -88,12 +120,24 @@ $(document).ready(function() {
    }
    });

    if (foo) {
    if (foo) { // <----- this is always undefined; the xhrGet call is async
    // run this important code
    }
    })();

    // A:

    (function() {
    dojo.xhrGet({
    url : 'foo.php',
    load : function(resp) {
    var foo = resp.foo;
    if (foo) {
    // run this important code
    }
    }
    });
    })();


    // 8: how could you rewrite the following code to make it shorter?
    @@ -104,6 +148,14 @@ $(document).ready(function() {
    $('li.bop a').attr('title', 'i am bop');
    })(dojo, dojo.query);

    // A:

    (function(d, $){
    var v = ['foo', 'bar', 'baz', 'bop'];
    for (var x in v) {
    $('li.'+v[x]+' a').attr('title', 'i am '+v[x]);
    }
    })(dojo, dojo.query);



    @@ -113,6 +165,18 @@ for (i = 0; i <= 100; i++) {
    $('#gizmo').append('<p><span class="gizmo">i am gizmo ' + i + '</span></p>');
    }

    // A: manipulating the DOM is expensive. using join('') is also more memory-
    // efficient that concatenating strings in a compund fashion

    var thingerVals = [],
    gizmoVals = [];
    for (i = 0; i <= 100; i++) {
    thingerVals.push('<p><span class="thinger">i am thinger ' + i + '</span></p>');
    gizmoVals.push('<p><span class="gizmo">i am gizmo ' + i + '</span></p>');
    }
    $('#thinger').append(thingerVals.join(''));
    $('#gizmo').append(gizmoVals.join(''));




    @@ -123,6 +187,11 @@ function calculateTotal(baseTotal, tip, tax, fee) {
    return baseTotal + tip + tax + fee;
    }

    // A: If the tip value is read straight from a text box, it'll be a string
    // and so will just be concatenated to the string representation of
    // baseTotal. This is toxic: as string+number results in a string, the
    // concatenation will continue for tax and fee. This can be mitigated by
    // sanatising tip with parseInt(tip, 10)



    @@ -165,11 +234,31 @@ var menuItems = [
    ];


    // A: (the resulting array is stored in result)

    var result = [],
    item;
    for(var i in menuItems) {
    item = menuItems[i];
    var itemText = item.name;
    if(item.extras && item.extras.length >0) {
    itemText += ' (' + item.extras.join(', ') + ')'
    }
    result.push(itemText);
    }


    // BONUS: write code such that the following alerts "Hello World"
    say('Hello')('World');

    // A:

    function say(a) {
    return function(b) {
    alert(a + ' ' + b);
    }
    }




    @@ -185,6 +274,12 @@ for (var i = 0; i <= 5; i++) {

    console.log('The next five days are ', dates.join(', '));

    // A: firstly, getMonth is zero-indexed, so it won't return the value that
    // is commonly used to number the month. Also, this code breaks on any day
    // less than five days before the end of the month, as it simply increments
    // the day (i.e. 8/29, 8/30, 8/31, 8/32, 8/33)




    /*
  3. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -167,6 +167,12 @@ var menuItems = [



    // BONUS: write code such that the following alerts "Hello World"
    say('Hello')('World');




    // BONUS: what is the faulty logic in the following code? how would you fix it?
    var date = new Date(),
    day = date.getDate(),
    @@ -181,7 +187,6 @@ console.log('The next five days are ', dates.join(', '));




    /*
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004
  4. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -177,4 +177,23 @@ for (var i = 0; i <= 5; i++) {
    dates.push(month + '/' + (day + i));
    }

    console.log('The next five days are ', dates.join(', '));
    console.log('The next five days are ', dates.join(', '));




    /*
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004
    Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
    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.
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
    0. You just DO WHAT THE FUCK YOU WANT TO.
    */
  5. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ var myObjects = {
    // 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 the library of your choice is
    // available
    // available)
    var myArray = [ 'foo', 'bar', 'baz' ];


  6. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -54,8 +54,8 @@ var myObjects = {
    // 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)
    // array item 'foo foo foo'. (you can assume the library of your choice is
    // available
    var myArray = [ 'foo', 'bar', 'baz' ];


    @@ -117,7 +117,7 @@ for (i = 0; i <= 100; i++) {


    // 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
    // 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;
    @@ -132,7 +132,7 @@ function calculateTotal(baseTotal, tip, tax, fee) {
    //
    // [ "Salad (Chicken, Steak, Shrimp)", ... ]
    //
    // (you can assume jQuery, dojo, or underscore are available)
    // (you can assume the library of your choice is available)
    var menuItems = [
    {
    id : 1,
  7. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 41 additions and 0 deletions.
    41 changes: 41 additions & 0 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -126,6 +126,47 @@ function calculateTotal(baseTotal, tip, tax, fee) {



    // 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 jQuery, dojo, or underscore are available)
    var menuItems = [
    {
    id : 1,
    name : 'Salad',
    extras : [
    'Chicken', 'Steak', 'Shrimp'
    ]
    },

    {
    id : 2,
    name : 'Potato',
    extras : [
    'Bacon', 'Sour Cream', 'Shrimp'
    ]
    },

    {
    id : 3,
    name : 'Sandwich',
    extras : [
    'Turkey', 'Bacon'
    ]
    },

    {
    id : 4,
    name : 'Bread'
    }
    ];




    // BONUS: what is the faulty logic in the following code? how would you fix it?
    var date = new Date(),
    day = date.getDate(),
  8. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -133,5 +133,7 @@ var date = new Date(),
    dates = [];

    for (var i = 0; i <= 5; i++) {
    dates.push(month + '/' + (day + i))
    }
    dates.push(month + '/' + (day + i));
    }

    console.log('The next five days are ', dates.join(', '));
  9. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ var myArray = [ 'foo', 'bar', 'baz' ];



    // 6: how could you potentially improve the following code?
    // 6: how could you improve the following code?
    $(document).ready(function() {
    $('.foo #bar').css('color', 'red');
    $('.foo #bar').css('border', '1px solid blue');
  10. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ var myArray = [ 'foo', 'bar', 'baz' ];



    // 6: what potential issues do you see with the following code? how would you fix it?
    // 6: how could you potentially improve the following code?
    $(document).ready(function() {
    $('.foo #bar').css('color', 'red');
    $('.foo #bar').css('border', '1px solid blue');
  11. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -97,10 +97,12 @@ $(document).ready(function() {


    // 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.bop a').attr('title', 'i am bop');
    (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);



  12. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ var foo = 'hello';

    // 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? howw would you affect the value of the bar
    // property for the variable bim? how would you affect the value of the bar
    // property for both foo and bim? how would you add a method to foo and bim to
    // console.log the value of each object's bar property? how would you tell if
    // the object's bar property had been overridden for the particular object?
  13. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,10 @@ var foo = 'hello';

    // 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?
    // property for the variable bim? howw would you affect the value of the bar
    // property for both foo and bim? how would you add a method to foo and bim to
    // console.log the value of each object's bar property? how would you tell if
    // the object's bar property had been overridden for the particular object?
    var Thinger = function() {
    return this;
    };
  14. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion screening.js
    Original file line number Diff line number Diff line change
    @@ -98,7 +98,6 @@ $(document).ready(function() {
    $('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');


    @@ -122,3 +121,13 @@ function calculateTotal(baseTotal, tip, tax, fee) {




    // 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))
    }
  15. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    // 1: assuming inputElement and otherElement are defined and are DOM nodes, how
    // could you rewrite the following to make it shorter?
    // 1: how could you rewrite the following to make it shorter?
    if (foo) {
    bar.doSomething(el);
    } else {
  16. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,6 @@ if (foo) {
    bar.doSomethingElse(el);
    }

    bar[foo ? 'doSomething' : 'doSomethingElse'](el);



    @@ -27,7 +26,7 @@ var foo = 'hello';
    // the bar property for both foo and bim?
    var Thinger = function() {
    return this;
    }
    };

    Thinger.prototype = {
    bar : 'baz'
    @@ -38,6 +37,7 @@ var foo = 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?
    @@ -49,6 +49,7 @@ var myObjects = {




    // 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
    @@ -74,6 +75,7 @@ $(document).ready(function() {




    // 7: what issues do you see with the following code? how would you fix it?
    (function() {
    var foo;
    @@ -92,6 +94,7 @@ $(document).ready(function() {




    // 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');
    @@ -101,17 +104,22 @@ $('li.bop a').attr('title', 'i am bop');




    // 9: how would you improve the following code?
    for (i = 0; i <= 5; i++) {
    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 thinger ' + i + '</span></p>');
    $('#gizmo').append('<p><span class="gizmo">i am gizmo ' + 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;
    }
    }



  17. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -101,8 +101,17 @@ $('li.bop a').attr('title', 'i am bop');



    // 9: how could you improve the following code?
    for (var i = 0; i <= 5; i++) {
    // 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;
    }
  18. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 32 additions and 15 deletions.
    47 changes: 32 additions & 15 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,16 @@
    // how could you rewrite the following to make it shorter?
    // 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);


    // what is the faulty logic in the following code?

    // 2: what is the faulty logic in the following code?
    var foo = 'hello';

    (function() {
    @@ -17,7 +20,8 @@ var foo = 'hello';



    // given the following code, how would you override the value of the bar

    // 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?
    @@ -34,7 +38,7 @@ var foo = new Thinger(),



    // given the following code, and assuming that each defined object has a
    // 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 = {
    @@ -45,23 +49,17 @@ var myObjects = {



    // given the following array, create an array that contains the contents of
    // 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'
    // array item 'foo foo foo'. (you can assume jQuery, dojo, or underscore is
    // available)
    var myArray = [ 'foo', 'bar', 'baz' ];



    // given the following array, write a code snippet that console.log's the
    // array item IF it is a string; if it is a number, console log "divisible by 3"
    // IF the number is divisible by 3
    var myArray = [ 'foo', 3, 5, 12, 7, 'seven' ];




    // what issues do you see with the following code?
    // 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');
    @@ -70,11 +68,13 @@ $(document).ready(function() {
    $(this).attr('title', 'new title');
    $(this).width('100px');
    });

    $('.foo #bar').click();
    });



    // what issues do you see with the following code? how would you fix it?
    // 7: what issues do you see with the following code? how would you fix it?
    (function() {
    var foo;

    @@ -89,3 +89,20 @@ $(document).ready(function() {
    // 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 could you improve the following code?
    for (var 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>');
    }
  19. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    // assuming inputElement and otherElement are defined and are DOM nodes, how
    // could you rewrite the following to make it shorter?
    // how could you rewrite the following to make it shorter?
    if (foo) {
    bar.doSomething(el);
    } else {
  20. @rmurphey rmurphey revised this gist Sep 13, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    // assuming inputElement and otherElement are defined and are DOM nodes, how
    // could you rewrite the following to make it shorter?
    if (dojo.attr(inputElement, 'checked')) {
    dojo.addClass(otherElement, 'bar');
    if (foo) {
    bar.doSomething(el);
    } else {
    dojo.removeClass(otherElement, 'bar');
    bar.doSomethingElse(el);
    }


  21. @rmurphey rmurphey created this gist Sep 13, 2010.
    92 changes: 92 additions & 0 deletions screening.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    // assuming inputElement and otherElement are defined and are DOM nodes, how
    // could you rewrite the following to make it shorter?
    if (dojo.attr(inputElement, 'checked')) {
    dojo.addClass(otherElement, 'bar');
    } else {
    dojo.removeClass(otherElement, 'bar');
    }



    // what is the faulty logic in the following code?
    var foo = 'hello';

    (function() {
    var foo = foo || 'world';
    console.log(foo);
    })();



    // 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();



    // 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()
    };



    // 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'
    var myArray = [ 'foo', 'bar', 'baz' ];



    // given the following array, write a code snippet that console.log's the
    // array item IF it is a string; if it is a number, console log "divisible by 3"
    // IF the number is divisible by 3
    var myArray = [ 'foo', 3, 5, 12, 7, 'seven' ];




    // what issues do you see with 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').click(function() {
    $(this).attr('title', 'new title');
    $(this).width('100px');
    });
    });



    // 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
    }
    })();