public
Last active

Some of the JavaScript puzzlers from VanJS (2013-07-11), as presented by Charles Bihis of Adobe.

  • Download Gist
1.js
JavaScript
1 2 3 4 5 6 7 8 9
var commodusRule = 'thumbsUp';
console.log('Maximus the ' + (commodusRule === 'thumbsUp') ? 'Gladiator' : 'Merciful');
 
// What does this print?
 
// A. "Maximus the Gladiator"
// B. "Maximus the Merciful"
// C. "Maximus the "
// D. None of the above
2.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var name = 'World!';
 
(function() {
if (typeof name === 'undefined') {
var name = 'Mr. Bond';
console.log('Goodbye, ' + name);
} else {
console.log('Hello, ' + name);
}
})();
 
// What does this print?
 
// A. "Hello, World!"
// B. "Hello, Mr. Bond"
// C. "Goodbye, Mr. Bond"
// D. "Goodbye, World!"
// E. None of the above
3.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function doStuff(name) {
switch (name) {
case 'A':
console.log('It is A');
break;
case 'B':
console.log('It is B');
break;
case 'C':
console.log('It is C');
break;
default:
console.log("We don't know!");
break;
}
}
 
doStuff(new String('A'));
 
// What does this print?
 
// A. "It is A"
// B. "It is B"
// C. "It is C"
// D. "We don't know"
// E. It varies
// F. None of the above
4.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
var zipcodes = ['39461', '02391', '56910', '09154', '74512'];
 
for (var i = 0; i < zipcodes.length; i++) {
if (!isNaN(parseInt(zipcodes[i])) && parseInt(zipcodes[i]) > 0) {
console.log(parseInt(zipcodes[i]));
}
}
 
// What does this print?
 
/* A. 39461
19
56910
74512
*/
/* B. 39461
2391
56910
9154
74512
*/
/* C. 39461
56910
74512
*/
// D. Error
// E. It varies
// F. None of the above
5.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var END = 9007199254740992; // Math.pow(2, 53)
var START = END - 100;
 
var count = 0;
for (var i = START; i <= END; i++) {
count++;
}
 
console.log(count);
 
// What does this print?
 
// A. 100
// B. 101
// C. Error
// D. None of the above

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.