Skip to content

Instantly share code, notes, and snippets.

@dpogue
Last active December 19, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpogue/5985869 to your computer and use it in GitHub Desktop.
Save dpogue/5985869 to your computer and use it in GitHub Desktop.
Some of the JavaScript puzzlers from VanJS (2013-07-11), as presented by Charles Bihis of Adobe.
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
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
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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment