JS test


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…:wink:

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…:wink:

(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…


thank you…

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.

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:

var availableSnowTires = [true, true, true, true, true],
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:

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.


:smiley: [/ot]

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.

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.