JavaScriptmancy - Basics - Functions - Exercises

Basic ways to declare functions in JavaScript - 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);
}

Babel + JSX

'use strict'
// 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
Chapter 02 - The Basics of JavaScript Functions - Exercises

*/

randalf.says('Oh no... we are going to die.');
mooleen.says('Wait? What? This is just a dream...');

randalf.says('Does the unbearable heat of that torrent of flames feel dreamy to you?');
mooleen.says('Damn...');
mooleen.says(`Well... JavaScriptmancer of the First Order,
guardian of the secret flame, can you do something!?`);

randalf.says('Sacred Flame...')
randalf.says('hmm I kind of ...ehem.. have lost my power');
mooleen.says('Shit');

narrate("=== ### Oh No! You Are About To Be Incinerated!? === ")
narrate("**Write a function expression** to cast a magic shield around you and protect you from sure death.")

var castMagicShield = function(target){
    console.log('The air shimmers around ' + target + ' as ' + 
    target + ' is surrounded by a magic shield');
    target.defense = 1000000;
}

mooleen.weaves('castMagicShield(mooleen)');
// => The air shimmers around Mooleen as Mooleen is surrounded by a magic shield
mooleen.weaves('castMagicShield(randalf)');
// => The air shimmers around Randalf, the Red as Randalf, the Red is surrounded by a magic shield

great.weaves('fireball(mooleen, randalf)');
// => A giant fireball blasts Mooleen and Randalf, the Red

/*
* While all the surrounding vegetation springs into flames
* the space surrouding Mooleen and Randalf remains eerily 
* intact.
*/

great.says(`What!? How are you alive?! It can't be! You old fool lost the ability to weave long ago`);
great.says(`It doesn't matter, If I cannot burn you, I'll bury you both`);

/*
*  The earth starts rumbling under your feet as Great concentrates...
*/

narrate("=== Tap Into the Source and Fight Back!=== ");
narrate("Hoisting can be problematic. Find the bug in these spell and release destruction upon...