Meaning: use const for fixed values; let for values that change.
Read the code
1const PI = 3.14159; // fixed2let count = 0; // changeable34count++;5Hero.say("I updated the counter to " + count + ".");
Live result
"I updated the counter to 1."
Story-style variant
Read the code
1const HOME = "camp";2let energy = 2;34Hero.exhaleSlow()5 .say("Back at " + HOME + ".");6energy--;7Hero.smileSoft()8 .say("I'll rest a bit — energy: " + energy + ".");
Live result
A slow breath at camp, then a tired but gentle smile: "I'll rest a bit — energy: 1."
03
Arrays [] — a group of characters or objects
Meaning: square brackets hold an ordered list.
Read the code
1let food = ["berries", "nuts", "fish"];2Hero.say("I see " + food.length + " foods in the box.");
He claims the first step with a steady voice: "Step 1." A moment later, shoulders sink and breath leaves slowly: "Back to 0."
05
if / else if / else — make a decision
Meaning: check a condition; if true → do A; else → do B.
Read the code
1const isRaining = true;23if (isRaining) {4 Hero.say("I take an umbrella.");5} else {6 Hero.say("I put on sunglasses.");7}89const age = 18;10if (age === 18) {11 Hero.say("I am exactly eighteen.");12}
Live result
"I take an umbrella." / "I am exactly eighteen."
Story-style variant
Read the code
1if (Hero.isHungry) {2 Hero.lookDown()3 .voiceShake()4 .say("I'm hungry…");5} else {6 Hero.smileSoft()7 .say("I'm fine for now.");8}
Live result
If hungry: eyes drop, voice trembles: "I'm hungry…". Otherwise: a soft smile and calm reply: "I'm fine for now."
06
Ternary ? : — a quick choice between two paths
Meaning: pick between two options in short form.
Read the code
1const temp = 27;2const outfit = temp > 20 ? "a T-shirt" : "a sweater";34Hero.say("I will wear " + outfit + ".");
He reads softly: "I read number 1.", then "I read number 2.", skips with a quick grin: "I skip 3.", turns the page: "I read number 4.", and closes the loop with: "I stop at 5."
Read the code
1functionfirstEven(arr: number[]) {2for (const x of arr) {3if (x % 2 === 0) return x;4 }5returnnull;6}78Hero.say("I find the first even: " + firstEven([1, 5, 7, 8, 9]) + ".");
Live result
He scans the numbers, then nods: "I find the first even: 8."
11
new — bring a new character into the story
Meaning: a class is a blueprint; new makes a fresh instance.
Read the code
1class Person {2constructor(public name: string) {}34greet() {5 Hero.say("Hi, I am " + this.name + ".");6 }7}89const p = newPerson("Hero");10p.greet();
Live result
A new figure steps forward and introduces himself: "Hi, I am Hero."
A pine torch sparks to life, glow catching in Hero's eyes: "I light a pine torch."
12
switch — tidy choice among many options
Nice when one variable can be many named cases.
Read the code
1const light = "yellow";23switch (light) {4case"red":5 Hero.say("I stop.");6break;7case"yellow":8 Hero.say("I get ready.");9break;10case"green":11 Hero.say("I go.");12break;13default:14 Hero.say("I don't know this signal.");15}
Live result
Yellow light glows ahead; Hero says: "I get ready."
Story-style variant
Read the code
1const weather = "windy";23switch (weather) {4case"sunny":5 Hero.smileSoft().say("I walk in the sun.");6break;7case"rainy":8 Hero.frownGently().say("I shelter under a tree.");9break;10case"windy":11 Hero.jawTighten().say("I tie my cloak.");12break;13default:14 Hero.lookAround().say("I wait and watch the sky.");15}
Live result
Wind tugs at his cloak; his jaw sets: "I tie my cloak."
13
Math.random() — simple randomness
Meaning: returns 0 ≤ n < 1.
Read the code
1const coin = Math.random() < 0.5 ? "heads" : "tails";2Hero.say("I flip a coin: " + coin + ".");34const die = Math.floor(Math.random() * 6) + 1;5Hero.say("I roll a die: " + die + ".");
Live result
For example: "I flip a coin: heads." / "I roll a die: 4."
With a playful grin he declares: "I feel good luck today!"
Next
Coming soon...
The full cinematic guide will grow into beat-maps, scenes, and multi-character choreography.
In the book, these basics power bigger patterns: nested story-variants, chapter-level logic beats, and whole journeys written as code. This page is just the first layer of the "How to watch the code as a movie" guide.
Enjoying the guide?
Support more reading tools
Support helps create more guides, story experiments, and reader-friendly tools for CodeXStory.