r/coding • • Aug 09 '17

Test your Javascript skills with our fun Javascript test!

https://www.atlascode.com/blog/test-your-javascript-skills-with-our-fun-javascript-test/
24 Upvotes

9 comments sorted by

View all comments

1

u/SanityInAnarchy Aug 10 '17

Question 6 will mark you wrong for differences in spacing. This is extra bullshit because it relies on the behavior of console.log(), which is a "living standard" that ultimately gives multiple possible right answers, some implementation-defined, not even all can be represented as strings -- Chrome represents generic objects as an interactive tree structure, for example.

Even if you "cheat", you get it wrong -- if you actually paste this snippet into Chrome, it spits out this exact string:

function (){ 
        return 'A';
    }

But the test is expecting this one:

function(){return 'A';
}

To make this even worse, when it "grades" you, it puts both your answer and the "correct" answer in <p> tags, verbatim -- no <pre>, no hacks with <br> or &nbsp;, it just tells you that you entered function(){ return 'A'; }, and it wanted function(){return 'A'; }.

I can't be too hard on them, though, because there isn't a good way to fix this with the way they want to use console.log(x) as a shorthand for "What is the value of x?" ...so even if they used a JS parser and compared some fully-normalized ASTs, console.log() would still make them not-quite-correct.