#PL3 - a test that failed for me despite passing the stage

var bar = 0;
var foo = (bar = (foo = 2)) + 1;
print bar;
print foo;

Because I failed to check variable declarations at runtime, my program output was

2
3

even though my code passed #PL3. I’ve since fixed my program so it outputs:

[line 2]: var foo = (bar = (foo = 2)) + 1;
                            ^^^

Runtime error: undefined variable 'foo'

In fact, any assignment of a global variable before its declaration doesn’t seem to be checked properly at the moment by the CodeCrafters tests, not just this weird same-declaration case.

1 Like