-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathboolean-expressions-and-conditional-statements.js
More file actions
52 lines (39 loc) · 1.62 KB
/
boolean-expressions-and-conditional-statements.js
File metadata and controls
52 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Objective:
You will practice creating and combining boolean expressions
to drive logic and outcomes in you program.
Instructions:
If you are not familiar with the concept of a text-based adventure game,
let's set the scene...
Example: "You wake up in a dark forest. There are two paths ahead of you:
one leading to the mountains and one to a village.
Your choices will determine your fate!"
Define the Requirements: You must:
- Write conditional statements to handle player choices.
- Use boolean expressions to combine multiple conditions.
- Include at least one use of logical operators (&&, ||, !).
Starter Code:
- Run the following command in your terminal to install the readline-sync module:
npm install readline-sync
Paste the following code into your editor:
*/
const readline = require('readline-sync');
const hasTorch = true;
const hasMap = false;
console.log("You see two paths: one leads to the mountains, the other to the village.");
const choice = readline.question("Do you go to the 'mountains' or the 'village'?");
if (choice === "mountains" && hasTorch) {
console.log("You safely navigate through the dark mountains.");
} else if (choice === "mountains" && !hasTorch) {
console.log("It's too dark to proceed. You decide to turn back.");
} else if (choice === "village" || hasMap) {
console.log("You find your way to the village.");
} else {
console.log("You get lost and wander aimlessly.");
}
/*
Add Customization and expand the game:
- Add more choices and scenarios.
- Include additional items (e.g., a sword, a compass).
- Use nested conditionals and logical operators to create complex outcomes.
*/