This week's assignment was inspired by Robert Frost's The Road Not Taken:
“Two roads diverged in a yellow wood…”
The prompt asked us to create an interactive program about difficult choices and use conditional statements to control the flow of the program. At first, I interpreted this assignment in a very literal way. I thought about choices as branching paths: one decision causes another consequence, which causes another consequence, eventually changing the entire system.
But later, I became more interested in doing the opposite. What if the entire project built up the importance of choice, only to prove at the end that none of those choices mattered at all?
Since the assignment focuses on conditional statements, I wanted the program structure itself to make those conditions visible.
The entire game is mainly controlled by one variable:
let state = 0;
The value of state determines which screen is currently displayed.
At the beginning of the code, I store most of the game's text inside arrays.
let questions = [
"Your child is very ill...",
"Your closest friend was wrongly imprisoned...",
"You are a journalist..."
];
let optionsA = [
"A. Save your child.",
"A. Hand over the evidence.",
"A. Publish the story."
];
let optionsB = [
"B. Save the company.",
"B. Keep it hidden.",
"B. Bury the story."
];
Instead of writing three separate sections of code for the three questions, I store the content as data.
I also created two arrays that record what each choice means:
let recordA = [
"You embezzled the company's funds to save your child.",
"You exposed your own crime to free your friend.",
"You exposed the company, knowing it would cost jobs."
];
let recordB = [
"You let the company survive, and your child went without the surgery.",
"You let your friend stay in prison to protect yourself.",
"You stayed silent to protect their jobs."
];
When the player selects an answer, the program saves the corresponding sentence into another array:
let picks = [];
stateThe most important part of the program is the state variable.