Question
Using Notepad++ and no HTML create a new file called godamongus30.js 1. We originally created multiple variables to store our addditional adventurers that our leader
Using Notepad++ and no HTML
create a new file called godamongus30.js
1. We originally created multiple variables to store our addditional adventurers that our leader travels with. Modify the adventurers variable to hold an array. Initialize the adventurers with six made up characters for your storyline. They can all be string names for now. Go back and modify your games introduction to display all the names of the adventures in the storyline. Use the array values for this, not hardcoded strings.
2. Create an array to store the inventory our leader will have available to them. Initialize it with atleast one item. The leader should only be able to carry a maximum of 5 items.
3. Last week, we created four options in the storyline for the user to choose from. This week modify atleast 2 of those options to give the user an additional item. The display should give the user the following choices:
a. Display Inventory( This option should display all the items in the users inventory) b. Pick up Item
If they do not have more than 5 already. If the leader has more than 5 items, ask them if they would like to trade for the new item. If so, switch the items.
Existing Code:
var adventurersName = ["George", " Tim", " Sarah", " Mike", " Edward"]; var adventurersKilled = 3; var survivors; var leader = "Captain Thomas King"; var numberOfAdventurers = adventurersName.length;
survivors = numberOfAdventurers - adventurersKilled;
console.log("Welcome to The God Among Us "); console.log("A group of adventurers began their search for the mystical god said to live among us. In charge of the squad was " + leader + " who was famous for his past exploits. Along the way, the group of comrades were attacked by the god's loyal followers. The adventurers fought with bravado and strength under the tutelage of " + leader + " the followers were defeated but they still suffered great losses. After a headcount of the remaining squad, " + adventurersKilled + " were found to be dead which left only " + survivors + " remaining survivors. ");
console.log("Current Statistics : "); console.log("Total Adventurers = " + numberOfAdventurers); console.log("Total Killed = " + adventurersKilled); console.log("Total Survived = " + survivors);
const prompt = require('prompt-sync')(); var user_life = 3; var correct_answer = ['1', '2', '3'] var userIsCorrect; var options = [" Option 1 Enter the village hut?", "Option 2 Eat the turkey leg?", "Option 3 Sit on the stool?", "Option 4 Talk with the shadowy figure? "];
var leader = prompt("Enter Leader Name: ")
while (user_life > 0) { user_life = game(leader, options);
if (user_life === 0) { var play_again = prompt("Do You Want Play Again (y/n)? ");
if (play_again == "y") { user_life = 3 var leader = prompt("Enter Leader Name:")
} else { console.log(` Game Ended! Bye!`) break; } } }
function game(leader, options) {
showOptions(options);
const input = prompt("Enter Your choice (Number) ");
userIsCorrect = (correct_answer.includes(input));
if (userIsCorrect) { console.log("Yay, you picked the right option. You rest a day and come to a new village that looks exactly the same. Which option do you choose?"); } else { user_life = user_life - 1; console.log("One Life is Lost!") } displayStats(user_life, leader);
return user_life;
}
function showOptions(option) { console.log(option[0]); console.log(option[1]); console.log(option[2]); console.log(option[3]); }
function displayStats(user_life, name) { console.log(` Current Statistics: Leader Name: ${name} Lives Remaining: ${user_life}`) console.log("Adventurers in your party = " + survivors); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started