JavaScriptmancy - Basics - Functions - Multiple Parameters

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 for C# Devs
Chapter 04 - The Basics of JavaScript Functions - Arbitrary Arguments

*/

narrate("An endless beach, the rumor of the sea, fire crackling nearby...");

randalf.says('It was a long time ago...');
randalf.says('Damn! Just thinking about it makes me feel ancient...');

randalf.says('The birth of JavaScript-mancy.');
randalf.says('I remember it clearly...');
randalf.says('I was there the very second it happened');

randalf.says(`
Branden was special. He looked at the world in a different light. He would often wander and ponder about the workings of the world and how to make it better for everyone. He would build wondrous inventions, some of them useless I'll grant, some of them even dangerous. He studied and pursuited his goals with a near mad passion and intent, and one day he found it. 

He found what would change the world for ever: JavaScript-mancy and 
the sacred REPL.
`);

mooleen.says('wait, wait... do you mean the Read-Evaluate-Print-Loop??');
randalf.says('What? No child, the REPL is just... well, the REPL');

randalf.says(`
Anyhow, historians always claim he was working on a great wonder when he found it. You know what? He wasn't!

He was boiling eggs!! He had made this useless machine to boil an egg and was racking his brain to boil an arbitrary number of eggs. Can you believe it?
`);

console.log("======== JavaScript, parameters and arguments ========\n");
// JavaScript is very flexible when handling parameters. You can define
// a function as taking a number of parameters and then call it without arguments

function heal(person, inchantation, modifier){
    var healedHp;
    modifier = modifier || 1;
    healedHp = modifier * 100;
    
    console.log('you heal ' + person + ' with ' + inchantation + ' spell (+' + healedHp + 'hp)' );
   ...