JavaScriptmancy - Basics - JavaScript Quirks and Gotchas Demystified - Exercises
JavaScript Quirks and Gotchas Demystified - Exercises
by vintharas
HTML
<pre><code id="theWorld">
</code></pre>
CSS
pre {
font-size: 0.9rem;
padding: 2%;
background: #333;
color: white;
}
pre .world {
display: block;
white-space: pre-wrap;
}
pre .world-error{
color: rgba(255,0,0,0.7);
}
pre .world-info {
color: grey;
font-style: italic;
padding: 10px 0;
}
pre .world-spell{
color: rgba(90,90,255,1);
}
JavaScript
// log stuff in the home-made console to the write in addition to
// logging it to the browser console
startWorld();
/*
JavaScript-mancy: Mastering the Arcane Art of Writing Awesome JavaScript for C# Devs
Chapter 07 - Mysteries of the JavaScript Arcana: JavaScript Quirks and Gotchas Demystified - Exercises
*/
narrate("\
The small group starts walking up the mountain trail slowly. The path becomes narrower and steeper as they gain altitude, the air colder and crispier until it starts snowing. All of the sudden the group is surrounded by a thick mist that removes any sense of time or orientation.\
\
The group continues walking for what feels like an eternity. Suddenly Bandalf stops. This makes Zandalf crash into him, Randalf into Zandalf and Mooleen into Randalf, Zandalf and Bandalf. Ordinarily this wouldn't have been a problem if it weren't for the six sand golems, the crazy monkey, the pterodactyl and the dozen of creatures that were following right behind.\
")
mooleen.says("That was awkward");
bandalf.says("We're here!");
narrate("\
As it by art of magic the mist starts disolving revealing an inmense cavern.\
");
randalf.says("Welcome to The Caves of Infinity, " +
"headquarters of the Resistance, last remnant of the High " +
"Order of JavaScript-mancy")
/* EXERCISES */
narrate("=== Find The Bug! Get Access to the JavaScript-NomiCon ===");
narrate(" The following piece of code has a bug. Fix the problem and gain access to the oh-so-powerful JavaScript-NomiCon! The most valued treaty of JavaScript-mancy known to men, elves, dwarves and gnomes alike. ");
/*
function LibraryOfTheHighOrder(){
this.books = [];
this.summonBooks = function(){
$.getJSON('https://api.myjson.com/bins/3tp73')
.then(function updateBooks(books){
this.books.push(...books);
// caBOOOOOOM!!!!
// ERROOOOOORRRR!!!
// Cannot read property push of undefined
for(let book of...