In your game console class add a start function. Start function will prompt user for an email address. Use a regular expression to validate that its a valid email address and prompt again until they enter valid one. Next, prompt user to enter credit card number. Use a regular expression to validate the credit card. Prompt them again until they enter a valid one. Existing Code: class Game { constructor(name){ this.name = name; } } class GameConsole{ constructor(){ this.games = []; }    load(){ var gameNames = ["Zelda", "Halo", "Mario", "The God Among Us\n"]; for (var i = 0; i < gameNames.length; i++) { let game = new Game(gameNames[i]); this.games.push(game); } }    log(){ console.log("Games Loaded:"); for (var i = 0; i < this.games.length; i++) { var name = this.games[i].name; console.log(name); } } } let gamecon = new GameConsole(); gamecon.load(); gamecon.log(); const prompt = require('prompt-sync')(); var adventurersName = ["Captain Thomas King","George","Tim","Sarah","Mike","Edward",]; var len = 0; var Inventory = new Array(5).fill(" "); Inventory[len++] = "Food"; Inventory[len++] = "Wine"; Inventory[len++] = "Horses"; Inventory[len++] = "Medicine"; var adventurersKilled = 3; var survivors; var numberOfAdventurers = adventurersName.length; survivors = numberOfAdventurers - adventurersKilled; displayIntroduction(); displayMenu(); getLeader(); var user_life = 3; var user_health = 100; var correct_answer = ["1","2","3"]; var userIsCorrect; var options = ["\nOption 1 Enter the village hut?","Option 2 Eat the turkey leg?","Option 3 Sit on the stool?","Option 4 Talk with the shadowy figure?\n"]; adventurersName[0] = prompt("Enter Leader Name: "); while (user_life>0) { user_life = game(adventurersName[0],options); if (user_life === 0) { var play_again = prompt("Do You Want Play Again (y/n)? "); if (play_again =="y") { user_life= 3;        user_health = 100; adventurersName[0] = prompt("Enter Leader Name:"); } else { console.log("Game Ended.Bye!"); break; } } if (user_health === 0) {    user_life= user_life-1;    user_health= 100; } else{ var play_continue = prompt("Do You Want continue the Play(y/n)? "); if (play_continue == "n") { console.log("Game Ended.Bye!"); break; } } } function getLeader(){ let name = prompt("Enter your name: "); return name; } function game(leader,options) { showOptions(options); userIsCorrect = 0; const input = prompt("Enter Your choice (Number) "); for(var i=0;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement functions and expressions into your existing code:

In your game console class add a start function. Start function will prompt user for an email address. Use a regular expression to validate that its a valid email address and prompt again until they enter valid one. Next, prompt user to enter credit card number. Use a regular expression to validate the credit card. Prompt them again until they enter a valid one.

Existing Code:

class Game {
constructor(name){
this.name = name;
}
}

class GameConsole{
constructor(){
this.games = [];
}
  
load(){
var gameNames = ["Zelda", "Halo", "Mario", "The God Among Us\n"];
for (var i = 0; i < gameNames.length; i++) {
let game = new Game(gameNames[i]);
this.games.push(game);
}
}
  
log(){
console.log("Games Loaded:");
for (var i = 0; i < this.games.length; i++) {
var name = this.games[i].name;
console.log(name);
}
}
}

let gamecon = new GameConsole();
gamecon.load();
gamecon.log();

const prompt = require('prompt-sync')();

var adventurersName = ["Captain Thomas King","George","Tim","Sarah","Mike","Edward",];
var len = 0;
var Inventory = new Array(5).fill(" ");
Inventory[len++] = "Food";
Inventory[len++] = "Wine";
Inventory[len++] = "Horses";
Inventory[len++] = "Medicine";

var adventurersKilled = 3;
var survivors;
var numberOfAdventurers = adventurersName.length;

survivors = numberOfAdventurers - adventurersKilled;

displayIntroduction();
displayMenu();
getLeader();

var user_life = 3;
var user_health = 100;
var correct_answer = ["1","2","3"];
var userIsCorrect;
var options = ["\nOption 1 Enter the village hut?","Option 2 Eat the turkey leg?","Option 3 Sit on the stool?","Option 4 Talk with the shadowy figure?\n"];

adventurersName[0] = prompt("Enter Leader Name: ");

while (user_life>0) {
user_life = game(adventurersName[0],options);

if (user_life === 0) {
var play_again = prompt("Do You Want Play Again (y/n)? ");

if (play_again =="y") {
user_life= 3;
       user_health = 100;
adventurersName[0] = prompt("Enter Leader Name:");
}
else {
console.log("Game Ended.Bye!");
break;
}
}

if (user_health === 0) {
   user_life= user_life-1;
   user_health= 100;
}

else{
var play_continue = prompt("Do You Want continue the Play(y/n)? ");
if (play_continue == "n") {
console.log("Game Ended.Bye!");
break;
}
}
}

function getLeader(){
let name = prompt("Enter your name: ");
return name;
}

function game(leader,options) {

showOptions(options);
userIsCorrect = 0;
const input = prompt("Enter Your choice (Number) ");

for(var i=0;i<correct_answer.length;i++)
if(correct_answer[i]==input)
{
userIsCorrect=1;
}

if (userIsCorrect) {
   console.log("Yay, you picked the right option. After you are finished, you take a look at some of the items around you and compare them to the items you already have, would you like to pick up one of them?");
   console.log("Your Inventory Items: ");
  
   for(var i=0;i<len;i++) {
       console.log(Inventory[i]+", ");
   }
  
   console.log("\nItems To Pick Up: ");
   console.log("1.Food\n2.Clothes\n3.Horses\n4.Weapons\n5.Wine");
var item = prompt("Choose an item to pick up: ");
if(item==1)
item="Food";
else if(item==2)
item="Clothes";
else if (item == 3)
item = "Horses";
else if (item == 4)
item = "Weapons";
else if (item == 5)
item = "Wine";

if(len == 5)
{
console.log("Your Inventory is full!");
var swap_option = prompt("DO you want to swap(y/n):");
if(swap_option == 'y')
{
console.log("Your Inventory Items: ");
for(var i=0;i<len;i++)
console.log(Inventory[i]+", ");
var swap = prompt("Pick one to swap: ");
for (var i = 0; i < len; i++)
{
if(Inventory[i] == swap)
{
Inventory[i]=item;
break;
}
}
}
}
else{
Inventory[len++]=item;
}
}
else{
doDamage();
}
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("\nCurrent Statistics:\nLeader Name: ",name,"\nUser Health: ",user_health,"\nLives Remaining: ",user_life);
console.log("Adventurers in your party = " + survivors);
}

function displayIntroduction() {

console.log("Welcome to The God Among Us\n");
console.log("A group of adventurers began their search for the mystical god said to live among us. In charge of the squad was " + adventurersName[0] + " 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 " + adventurersName[0] + " 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.\n");
console.log("Current Statistics :\n");
console.log("Total Adventurers = " + numberOfAdventurers);
console.log("Adventures Names:");


for (var i = 0; i < numberOfAdventurers; i++)
  
console.log("\t" + adventurersName[i] + ", ");
console.log("Total Killed = " + adventurersKilled);
console.log("Total Survived = " + survivors);

}

function displayMenu() {

}

function doDamage() {
   user_health= user_health-25;
console.log("Health is Lost!") }

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education