SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: JS test....

  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    792
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    JS test....

    hi,

    I recently took a JS test.. obviously I didn't get all questions (and not only that, but the ones with code in them, the code is very hard to read.... it's a terribly-designed test... the code is an image, not plain text.. the b*stards....;-)

    I made a screenshot of questions I couldn't answer...

    was just wondering if I could get some help.. I already took the test, this is obviously so I can learn (but also for future reference....;-)

    (the one about testing for equality, the answer is "c" right? unless you're testing a string (but in theory you can also use '==' for testing strings, right?)

    q's are here...

    http://mayacove.com/dev/js_qs/js_qs.html


    thank you...

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    That looks like it is a really antiquated test. A lot of the code there is written the old way that JavaScript used to be written back before the DOM was created.

    Don't use new Array() to create an array - use [] instead.

    Never use == or != except where you are comparing a value with a version of itself (eg. x == +x to test if the value is numeric) otherwise you end up with things being considered to be equal that are not (eg. '' == 0 is true but an empty string is not the same as zero). Instead you should use === and !== which will correctly detect if they are the same. Only === compares for equality, == only tests for equal value and not for same type.

    Only use alert() for debugging - they should always be stripped out before a script goes live or some of your visitors can use it to turn off scripts for your page.

    onclick() is all lowercase - there is no capital C in it - also specify the JavaScript in the .js file not in the .html one.

    You should declare all of your variables at the very top of each function as that's where JavaScript will declare them anyway regardless of where in the function you put the declaration. The only statement to put above the declaration is "use strict"; to force an error if any variables are not declared.

    So with just about all of those questions either the code in the question is garbage or none of the answers are correct. Anyone able to complete that test will simply prove that they do not in fact properly understand JavaScript as they will have answered questions where none of the answers are correct.

    Unfortunately there are not only sites offering 20th Century JavaScript tests like that one but there are also sites (and college classes) that teach how to write JavaScript for the 20th Century and not the very different way that JavaScript should be written to work with modern browsers such as IE5 and more recent browsers.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by maya90 View Post
    hi,

    I recently took a JS test.. obviously I didn't get all questions (and not only that, but the ones with code in them, the code is very hard to read....
    Yes, not only is the code hard to read, but some parts of it are incorrect. Such as using "1 < snowTires.length" which should be an i instead.

    With that first question though, I might code it like this instead:

    Code javascript:
    var availableSnowTires = [true, true, true, true, true],
        i,
        isAvailable;
    for (i = 0; 1 < availableSnowTires.length; i += 1) {
        isAvailable = availableSnowTires[i] ? 'is' : 'is not';
        window.alert("snowTires " + isAvailable + " available.");
    }


    Or maybe even if backwards compatibility is less of an issue, like this:

    Code javascript:
    var availableSnowTires = [true, true, true, true, true];
    availableSnowTires.forEach(function (available) {
        var isAvailable = available ? 'is' : 'is not';
        window.alert("snowTires " + isAvailable + " available.");
    });

    But regardless, you can answer that first question by ruling out the answers which don't apply to the situation.

    All the best with your test.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,601
    Mentioned
    411 Post(s)
    Tagged
    7 Thread(s)
    Off Topic:

    Quote Originally Posted by paul_wilkins View Post
    I might code it like this instead:

    Code javascript:
    1 < availableSnowTires.length

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    It may well be be a test that also checks how much attention is being paid. This being the one (1) in question:



    I would answer E, with an answer that goes in to detail about the situation there, because the code as presented is none of the above. Well - arguably it's A, but it doesn't behave in the way that you would expect to normally use.

    I hope that you test it on a web browser that you can break out of when the alerts can't be stopped from occurring.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    792
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    oh brother.. this is not very encouraging... thank you everyone for their response......

    I mean when you think that in some instances people who don't pass these tests that were designed like a decade ago are denied a job? based on this stone-age test?

    I've also taken their HTML test.. guess what?? it's HTML 4!!!! every time I take their HTML4 test I write to them afterwards telling them they need to "get with the times".. the first time I wrote to them about this was about two or three years ago.. of course their HTML test is still HTML 4 (last time I took it, about a year ago, maybe...)

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by maya90 View Post
    oh brother.. this is not very encouraging... thank you everyone for their response......

    I mean when you think that in some instances people who don't pass these tests that were designed like a decade ago are denied a job? based on this stone-age test?

    I've also taken their HTML test.. guess what?? it's HTML 4!!!! every time I take their HTML4 test I write to them afterwards telling them they need to "get with the times".. the first time I wrote to them about this was about two or three years ago.. of course their HTML test is still HTML 4 (last time I took it, about a year ago, maybe...)
    It is important though to know all about HTML4 though, because many people are using web browsers that don't know how to do HTML5 things.

    If you were coming across HTML 3.2 code though, then that would give me cause for pause.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •