Day 3 — Continued

Ron Kagan
An Actor Codes
Published in
2 min readJul 20, 2018

I Made a Magic Eight Ball!

What’s happening here?

  1. You’re seeing Git Bash (for Windows) run a JavaScript file I’ve coded that works as a Magic Eight Ball.
  2. The JavaScript file is below:
//Magic Eight Ball
let userName = 'Ron';
userName !=='' ? console.log(`Hello ${userName}!`) : console.log('Hello!');
const userQuestion = 'Will I become a werewolf tonight?';
console.log(`${userName} asked ${userQuestion}`);
const randomNumber = Math.floor(Math.random() * 8);
let eightBall = '';
switch (randomNumber) {
case 0:
eightBall = 'it is certain';
break;
case 1:
eightBall = 'It is decidedly so';
break;
case 2:
eightBall = 'Reply hazy try again';
break;
case 3:
eightBall = 'Cannot predict now';
break;
case 4:
eightBall = 'Do not count on it';
break;
case 5:
eightBall = 'My sources say no';
break;
case 6:
eightBall = 'Outlook not so good';
break;
case 7:
eightBall = 'It is decidedly so';
break;
case 8:
eightBall = 'Signs point to yes';
break;
default:
eightBall = 'Reply hazy try again.';
break;
}
console.log(eightBall);

3. Here’s what going on:

i. The user, (in this case,Ron), gets a friendly “Hello, Ron!” or if the username is blank, it’s just “Hello!”

ii. You’ve got the question getting printed to the screen “Ron asked will I become a werewolf tonight?”

iii. Then you’ve got the logic that assigns an answer based on the program picking a number randomly.

Some thoughts

Now, look, I know that this is no masterpiece… I realize that there are mistakes in the above but the fact is it’s basically working and served its purpose as practice for the concept of control flow (e.g. given a condition, execute one block of code or another).

How does control flow relate to acting? It’s about choices. What is it that makes it seem like the code above is alive somehow? Why is it that characters on a page or a stage seem somehow endowed with an immortal spark? It’s the capacity to imagine alternative outcomes that holds a kind of magic worth studying.

--

--