So I have a small RPG im coding (well I started it ages ago and gave up but have just come back for naother look!). I have a main character (just one so far):
var heroes = [{
name: 'Mary',
health: 15,
weapon: 'sword',
damage: 8,
dodge: 8,
backpack: 'water',
experience: 5
}];
Can I add extra items to the backpack or as I suspect (the below) is this the wrong way of storing the information as I get an error.
backpack: 'water', 'bread', 'cheese',
Secondly and related... I have a function to fight an enemy. When it is defeated the content of their backpack would be pushed to the hero's backpack. I thought something like the below would work, but again Im clearly wrong :)
All help gratefully accepted :)
Full code:
<h1>
<b>RPG Battle</b>
</h1>
<p><button id="fight">Fight</button><button id="reset">Reset</button></p>
<div id="output"></div>
<script>
var enemies = [{
name: 'Wizard',
health: 10,
weapon: 'his staff.',
damage: 12,
dodge: 10,
backpack: 'Cloak of Invisibility....'
},
{
name: 'Elf',
health: 4,
weapon: 'a dagger.',
damage: 6,
dodge: 8,
backpack: 'a bow & Arrow....'
},
{
name: 'Dragon',
health: 20,
weapon: 'a fireball.',
damage: 15,
dodge: 2,
backpack: 'a golden key...'
},
{
name: 'Goblin',
health: 12,
weapon: 'his bow and arrow....',
damage: 4,
dodge: 6,
backpack: 'gold coins....'
},
{
name: 'Dwarf',
health: 7,
weapon: 'his axe.',
damage: 5,
dodge: 4,
backpack: 'a treasure map....'
},
{
name: 'Orc',
health: 8,
weapon: 'a sword.',
damage: 5,
dodge: 5,
backpack: 'a silver tooth....'
},
{
name: 'Witch',
health: 6,
weapon: 'her potion of the undead....',
damage: 7,
dodge: 6,
backpack: 'a potion of the living....'
},
{
name: 'Old Lady',
health: 3,
weapon: 'her frying pan.',
damage: 1,
dodge: 1,
backpack: 'some fruit and vegetables....'
},
{
name: 'Villagers',
health: 15,
weapon: 'sharpened sticks.',
damage: 5,
dodge: 1,
backpack: 'some meat....'
},
{
name: 'Thief',
health: 4,
weapon: 'his fists.',
damage: 3,
dodge: 9,
backpack: 'a bag of jewels....'
}
];
var heroes = [{
name: 'Mary',
health: 15,
weapon: 'sword',
damage: 8,
dodge: 8,
backpack: '',
experience: 5
}];
function getRandomElement(list) {
return Object.create(list[Math.floor(Math.random() * list.length)]);
}
function getRandomEnemy() {
return getRandomElement(enemies);
}
function getRandomHero() {
return getRandomElement(heroes);
}
var x, randomEnemy, hero;
var output = document.getElementById("output");
var fightBtn = document.getElementById("fight");
var resetBtn = document.getElementById("reset");
fightBtn.addEventListener("click", battle);
function reset() {
x = 1;
randomEnemy = getRandomEnemy();
fightBtn.disabled = false;
hero = getRandomHero();
output.innerHTML = "";
}
resetBtn.addEventListener("click", reset);
reset();
function battle() {
if (hero.health <= 0 || randomEnemy.health <= 0) {
fightBtn.disabled = true;
return;
}
var enemyDamage = Math.floor((Math.random() * (randomEnemy.damage)) + 1);
var enemyDodge = Math.floor((Math.random() * (randomEnemy.dodge)) + 1);
var randomNumber = Math.floor(Math.random() * 7) + 1;
var heroDodge = [Math.floor(Math.random() * hero.dodge)];
var heroDamage = Math.floor((Math.random() * hero.damage) + 1);
var heroExperience = Math.floor(Math.random() * 5) + 1;
output.innerHTML += "<br>" + "<b>" + "Round " + x++ + "</b>";
output.innerHTML += "<br>" + "The " + randomEnemy.name + " attacks you with " + randomEnemy.weapon;
if (randomNumber < heroDodge) {
output.innerHTML += "<br>" + "You evade the attack!";
} else if (hero.health > 0) {
hero.health = hero.health - enemyDamage;
if (hero.health < 0)
hero.health = 0;
output.innerHTML += "<br>" + "The " + randomEnemy.name + " did " + enemyDamage + " damage";
output.innerHTML += "<br>" + "You have " + hero.health + " health remaining.";
}
if (hero.health <= 0) {
output.innerHTML += "<br>" + "You have been killed by the " + randomEnemy.name;
fightBtn.disabled = true;
return;
} else {
output.innerHTML += "<br>" + hero.name + " attacks the " + randomEnemy.name + " with their " + hero.weapon;
}
if (randomNumber < enemyDodge) {
output.innerHTML += "<br>" + "The " + randomEnemy.name + " evades the attack!";
} else if (randomEnemy.health > 0) {
randomEnemy.health = randomEnemy.health - heroDamage;
if (randomEnemy.health < 0)
randomEnemy.health = 0;
output.innerHTML += "<br>" + hero.name + " did " + heroDamage + " damage";
output.innerHTML += "<br>" + "The " + randomEnemy.name + " has " + randomEnemy.health + " health";
}
if (randomEnemy.health <= 0) {
output.innerHTML += "<br>" + "The " + randomEnemy.name + " dies! You find " + randomEnemy.backpack;
output.innerHTML += "<br>"
output.innerHTML += "<br>" + "You gain " + heroExperience + " XP";
output.innerHTML += "<br>" + "You have " + hero.health + " health left";
output.innerHTML += "<br>" + hero.backpack.push(randomEnemy.backpack);
output.innerHTML += "<br>" + "Your backpack contains " + hero.backpack;
fightBtn.disabled = true;
}
}
</script>
initialization of the hero should be:
var heroes = [{
name: 'Mary',
health: 15,
weapon: 'sword',
damage: 8,
dodge: 8,
backpack: ['water', 'some other stuff'], //empty backpack is ['']
experience: 5
}];
Now the backpack is an array you can push into.
So after the replies above I managed to work out (guess) that the line reading:
output.innerHTML += "<br>" + hero.backpack.push(randomEnemy.backpack);
should be changed to:
output.innerHTML += "<br>" + hero.backpack.push([randomEnemy.backpack]);
Related
I have an exercise where from an object constructor, I have created several objects, all with an ID property.
The first part of the exercise consist in pairing each object, compare their markAv properties and print the one that had it bigger.
[ a vs b => b wins]
They suggested to do so by using the ID property but I didn't know how to do it that way... so I tried a workaround, as you will see in the code below.
However, the second part of the exercise wants me to do the same but, this time, creating the pairs randomly. Here I have tried to use the ID property by generating a random number that matches the ID but I don´t know how to structure the code for it to work.
The output for the second part should be the same as above, with the only difference that the pairing is now randomly generated.
I have added a partial solution for the second part, partial because from time to time it throws an error that I can´t identify. However, I think I'm getting close to get my desired output.
I would really appreciate if anyone could give me a hint for me to crack the code below and to get it working because I really want to understand how to do this.
class Avenger {
constructor(name, classRoom, city, job, studies, markAv, id) {
this.name = name;
this.classRoom = classRoom;
this.city = city;
this.job = job;
this.studies = studies;
this.markAv = markAv;
this.id = id;
}
heroList() {
return this.name + " " + this.classRoom + " " + this.city + " " + this.job + " " + this.studies + " " + this.markAv + " " + this.id
}
}
const tonyStark = new Avenger("Tony Stark", "XI", "NYC", "Ingeneer", "MIT", 10, 1)
const hulk = new Avenger("Hulk", "X", "Toledo", "Destroyer", "Scientific", 7, 2)
const daredevil = new Avenger("Daredevil", "IX", "NYC", "Lawyer", "Fighter", 2, 3)
const magneto = new Avenger("Magneto", "XXI", "SBD", "Unemployed", "Driver", 5, 4)
const unknown = new Avenger("Unknown", "L", "CDY", "President", "Clerck", 17, 5)
const xavi = new Avenger("Xavi", "XX", "BCN", "Analist", "Calle", 7, 6)
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
function getPairs(array) {
function getPairs(array) {
for (let i = 0; i < array.length; i += 2) {
if (array[i].markAv < array[i + 1].markAv) {
console.log(array[i].name + " vs " + array[i + 1].name + " " + array[i + 1].name + " Wins")
} else if (array[i].markAv > array[i + 1].markAv) {
console.log(array[i].name + " vs " + array[i + 1].name + " " + array[i].name + " Wins")
}
}
}
getPairs(heroes)
///
function randomAv(array) {
let result = []
let hero1 = heroes[Math.floor(Math.random() * 6) + 1]
for(let i = 0; i<array.length; i++){
if (array[i].markAv <= hero1.markAv && array[i].id != hero1.id) {
result.push(console.log(array[i].name + " vs " + hero1.name + " " + array[i].name + " Wins"))
} else if(array[i].markAv >= hero1.markAv && array[i].id != hero1.id) {
result.push(console.log(array[i].name + " vs " + hero1.name + " " + hero1.name + " Wins"))
}
}
console.log(result)
}
First shuffle the array:
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
let heroes_shuffle = heroes.sort((a, b) => 0.5 - Math.random())
Then do as normal
getPairs(heroes_shuffle )
All Possible Combination :
function allPairs(heroes) {
while (heroes) {
[hero, ...heroes] = heroes
for (enemy of heroes) {
if (hero.markAv === enemy.markAv)
console.log(hero.name + " vs " + enemy.name + ": draw")
else if (hero.markAv < enemy.markAv)
console.log(hero.name + " vs " + enemy.name + ": " + enemy.name + " Wins")
else
console.log(hero.name + " vs " + enemy.name + ": " + hero.name + " Wins")
}
}
}
You can take the function from here https://stackoverflow.com/a/7228322/1117736
And do something like this:
class Avenger {
constructor(name, classRoom, city, job, studies, markAv, id) {
this.name = name;
this.classRoom = classRoom;
this.city = city;
this.job = job;
this.studies = studies;
this.markAv = markAv;
this.id = id;
}
heroList() {
return this.name + " " + this.classRoom + " " + this.city + " " + this.job + " " + this.studies + " " + this.markAv + " " + this.id
}
}
const tonyStark = new Avenger("Tony Stark", "XI", "NYC", "Ingeneer", "MIT", 10, 1)
const hulk = new Avenger("Hulk", "X", "Toledo", "Destroyer", "Scientific", 7, 2)
const daredevil = new Avenger("Daredevil", "IX", "NYC", "Lawyer", "Fighter", 2, 3)
const magneto = new Avenger("Magneto", "XXI", "SBD", "Unemployed", "Driver", 5, 4)
const unknown = new Avenger("Unknown", "L", "CDY", "President", "Clerck", 17, 5)
const xavi = new Avenger("Xavi", "XX", "BCN", "Analist", "Calle", 7, 6)
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
let hero1 = heroes[randomIntFromInterval(1, 6)]
let hero2 = heroes[randomIntFromInterval(1, 6)]
if (hero1.markAv < hero2.markAv) {
console.log(hero1.name + " vs " + hero2.name + " " + hero1.name + " Wins")
} else if(hero1.markAv > hero2.markAv) {
console.log(hero1.name + " vs " + hero2.name + " " + hero2.name + " Wins")
}
I am new in programming and I want to create a Black Jack Game using JavaScript, but I have a problem, when the game start and the first hand is served if the player wants to "hit" more than once, the value of player_total2 doubles and is not accumulating, below is my code:
var player_total;
var player_total2;
var player_total3;
var player_card1;
var player_card2;
var firstPlay;
var secondPlay;
var welcome = confirm("Welcome to ♠ BalckJack ♥, the goal of the game is to get 21 points, you have the options to hit or stand.");
var message;
var card_dealt;
var card_deck = [
["Ace-H", 1],
["2-H", 2],
["3-H", 3],
["4-H", 4],
["5-H", 5],
["6-H", 6],
["7-H", 7],
["8-H", 8],
["9-H", 9],
["10-H", 10],
["Jack-H", 10],
["Queen-H", 10],
["King-H", 10],
["Ace-S", 1],
["2-S", 2],
["3-S", 3],
["4-S", 4],
["5-S", 5],
["6-S", 6],
["7-S", 7],
["8-S", 8],
["9-S", 9],
["10-S", 10],
["Jack-S", 10],
["Queen-S", 10],
["King-S", 10],
["Ace-D", 1],
["2-D", 2],
["3-D", 3],
["4-D", 4],
["5-D", 5],
["6-D", 6],
["7-D", 7],
["8-D", 8],
["9-D", 9],
["10-D", 10],
["Jack-D", 10],
["Queen-D", 10],
["King-D", 10],
["Ace-C", 1],
["2-C", 2],
["3-C", 3],
["4-C", 4],
["5-C", 5],
["6-C", 6],
["7-C", 7],
["8-C", 8],
["9-C", 9],
["10-C", 10],
["Jack-C", 10],
["Queen-C", 10],
["King-C", 10]
];
if (welcome === true) {
shuffle(card_deck);
player_card1 = card_deck.pop();
player_card2 = card_deck.pop();
player_total = cardValue(player_card1) + cardValue(player_card2);
if (player_total == 21) {
message = console.log("Your card total is " + player_total + ". Congratulations! You win!!!");
} else {
firstPlay = prompt("You hand is " + cardName(player_card1) + " and " + cardName(player_card2) + ". Your card total is " + player_total + ". Do you want to hit or stand?");
}
if (firstPlay === "hit") {
card_dealt = card_deck.pop();
player_total2 = player_total + cardValue(card_dealt);
while (player_total2 < 21 && secondPlay !== "stand") {
var secondPlay = prompt("You got now a " + cardName(card_dealt) + ". Your card total is " + player_total2 + ". Do you want to hit or stand?");
if (secondPlay === "hit") {
card_dealt = card_deck.pop();
player_total2 = player_total2 + player_total + cardValue(card_dealt);
}
}
if (secondPlay === "stand") {
message = console.log("Your total card value is " + player_total2 + ".");
} else if (player_total2 > 21) {
message = console.log("You got a " + cardName(card_dealt) + ". Your total card value is " + player_total2 + ". You lost!");
}
} else {
message = console.log("Your total card value is " + player_total + ".");
}
}
function cardValue(card) {
return card[1];
}
function cardName(card) {
return card[0];
}
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
}
if (firstPlay === "hit") {
card_dealt = card_deck.pop();
player_total2 = player_total + cardValue(card_dealt);
while (player_total2 < 21 && secondPlay !== "stand") {
var secondPlay = prompt("You got now a " + cardName(card_dealt) + ". Your card total is " + player_total2 + ". Do you want to hit or stand?");
if (secondPlay === "hit") {
card_dealt = card_deck.pop();
Here is your problem
player_total2 = player_total2 + player_total + cardValue(card_dealt);
player_total2 already has the player_total, and you are adding it again.
}
}
if (secondPlay === "stand") {
message = console.log("Your total card value is " + player_total2 + ".");
} else if (player_total2 > 21) {
message = console.log("You got a " + cardName(card_dealt) + ". Your total card value is " + player_total2 + ". You lost!");
}
} else {
message = console.log("Your total card value is " + player_total + ".");
}
I'm working in a backend with NodeJS and Mysql, everything is good but recently I've faced a small details where I'm stuck since added a SUBQUERY.
This is the Mysql Query:
var GetHistoryPayments = function(code){
var query = "SELECT DISTINCT students.student_code, " +
"acc.id, " +
"acc.StudentCode, " +
"acc.DocumentDate1, " +
"acc.DocEntry, " +
"acc.DocumentNumber1, " +
"acc.DocTotal1, " +
"acc.GrosProfit, " +
"acc.SumApplied, " +
"acc.DocumentDate2, " +
"acc.DocumentNumber2, " +
"acc.DiffDocTotalPaidToDate as total_pay, " +
"acc.LicTradNum, " +
"acc.created_at, " +
"acc.updated_at, " +
"(SELECT COUNT(*) FROM sap_accounting_state aa WHERE aa.DocumentNumber1 = acc.DocumentNumber1 and aa.tipo like 'Nota%' and aa.SumApplied > 0 ) as credit_notes " +
"FROM sap_accounting_state_students students INNER JOIN sap_accounting_state acc ON students.student_code = acc.StudentCode " +
"WHERE acc.DiffDocTotalPaidToDate = 0 " +
"and acc.Orden = 1 " +
"and acc.DocumentDate1 > '2018-06-01' " +
"and acc.StudentCode = '" + code + "' " +
"GROUP BY acc.DocumentNumber1 " +
"ORDER BY acc.DocumentDate1 desc";
return query;
}
The Object array returned is ok, but the SUBQUERY Object is really weird, it returns with a empty name ('': { credit_notes: 0 }). I suppose the SUBQUERY creates a new object with a known name. ¿How could access a '' json element?, how could put a name SUBQuery like: 'sub': { credit_notes: 0 }?.
Thanks.
[ RowDataPacket {
students: { student_code: '18018' },
acc:
{ id: 3836,
StudentCode: '18018',
DocumentDate1: 2019-01-01T05:00:00.000Z,
DocEntry: 74998,
DocumentNumber1: 10042438,
DocTotal1: 1839017,
GrosProfit: 1839017,
SumApplied: 0,
DocumentDate2: null,
DocumentNumber2: 0,
total_pay: 0,
LicTradNum: '79593354',
created_at: 2019-01-18T19:48:23.000Z,
updated_at: 2019-01-18T19:48:23.000Z },
'': { credit_notes: 0 } },
RowDataPacket {
students: { student_code: '18018' },
acc:
{ id: 3842,
StudentCode: '18018',
DocumentDate1: 2018-12-06T05:00:00.000Z,
DocEntry: 72048,
DocumentNumber1: 10039576,
DocTotal1: 346500,
GrosProfit: 346500,
SumApplied: 0,
DocumentDate2: null,
DocumentNumber2: 0,
total_pay: 0,
LicTradNum: '79593354',
created_at: 2019-01-18T19:48:23.000Z,
updated_at: 2019-01-18T19:48:23.000Z },
'': { credit_notes: 1 } } ... ]
Just take brackets as property accessor.
var item = { '': 'foo' };
console.log(item['']);
This question already has answers here:
Why is there "undefined" text in the beginning of my string?
(3 answers)
Closed 4 years ago.
I have a code like this:
var students = [
{
name: 'Mustafa',
track: 'A',
achievements: 5,
points: 500
},
{
name: 'Ersin',
track: 'B',
achievements: 6,
points: 600
},
{
name: 'Ahmet',
track: 'C',
achievements: 7,
points: 700
},
{
name: 'Mehmet',
track: 'D',
achievements: 8,
points: 800
},
{
name: 'Cafer',
track: 'E',
achievements: 9,
points: 900
}
];
var HTML;
var s = 0;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
for (var s = 0; s < students.length; s += 1) {
HTML += '<h2>' + 'Student: ' + students[s].name + '</h2>' ;
HTML += '<p>' + 'Track: ' + students[s].track + '</p>';
HTML += '<p>' + 'Points: ' + students[s].points + '</p>';
HTML += '<p>' + 'Achievements: ' + students[s].achievements + '</p>';
};
print(HTML);
<div id="output"></div>
Unfortunately, only bad-outcome for this code is an "undefined" at the beginning. I would like to get rid of this.
Is it something about my loop or any other detail that i couldn't predict?
var HTML;
You don't explicitly give the variable a value when you initialise it, so it is undefined.
The first time you append to the variable with +=, that value gets implicitly converted to the string "undefined".
Use var HTML = ""; instead.
Initialize HTML to "", you are getting undefined since HTML (since it is not initialized) is undefined
var HTML = ""; //change this line
Demo
var students = [
{
name: 'Mustafa',
track: 'A',
achievements: 5,
points: 500
},
{
name: 'Ersin',
track: 'B',
achievements: 6,
points: 600
},
{
name: 'Ahmet',
track: 'C',
achievements: 7,
points: 700
},
{
name: 'Mehmet',
track: 'D',
achievements: 8,
points: 800
},
{
name: 'Cafer',
track: 'E',
achievements: 9,
points: 900
}
];
var HTML = ""; //change this line
var s = 0;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
for (var s = 0; s < students.length; s += 1) {
HTML += '<h2>' + 'Student: ' + students[s].name + '</h2>' ;
HTML += '<p>' + 'Track: ' + students[s].track + '</p>';
HTML += '<p>' + 'Points: ' + students[s].points + '</p>';
HTML += '<p>' + 'Achievements: ' + students[s].achievements + '</p>';
};
print(HTML);
<div id="output"></div>
Initialize HTML variable with an empty string like this:
var HTML="";
I am currently trying to make one easy card comparison game but I am having some problems. When ever the var playerLife or computerLife == 0 I want to show a alert message and refresh the page for a new game. If you scroll down you can see that I am trying to do this using the if statment but it does not seem to work. I am quite new at this so all the help and tips are welcome. Also if this code that I have at the moment can be better I should love to hear it. Thanks for your time.
var cards = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,8, 9, 9, 10, 10];
var shuffledCards = shuffle(cards);
var playerDeck = shuffledCards.slice(0,20);
var computerDeck = shuffledCards.slice(20);
var playerlife = 25;
var computerLife = 25;
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
function getTopCard(deck) {
return deck[0];
}
function dealCards() {
var playerTopCard = getTopCard(playerDeck);
var computerTopCard = getTopCard(computerDeck);
var cardImage = "<img src='http://i1194.photobucket.com/albums/aa365/Sarah_Dunlap/card_back.png'/>";
whoWon();
console.log('--------------------');
document.getElementById("card1").innerHTML = "<div class='cardNumber'>" + playerTopCard + '</div>' + cardImage;
document.getElementById("card2").innerHTML = "<div class='cardNumber'>" + computerTopCard + '</div>' + cardImage;
document.getElementById("scoreComputer").innerHTML = computerLife;
document.getElementById("scorePlayer").innerHTML = playerlife;
}
function whoWon() {
var playerTopCard = getTopCard(playerDeck);
var computerTopCard = getTopCard(computerDeck);
if (playerTopCard > computerTopCard) {
console.log('Player Won! ' + playerTopCard + '/' + computerTopCard);
computerLife = computerLife - (playerTopCard - computerTopCard);
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
} else if (playerTopCard < computerTopCard) {
console.log('Computer Won! ' + playerTopCard + '/' + computerTopCard);
playerlife = playerlife - (computerTopCard - playerTopCard);
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
} else {
console.log('Tie! ' + playerTopCard + '/' + computerTopCard);
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
}
}
shuffle(cards);
console.log('playerDeck - ' + playerDeck);
console.log('computerDeck - ' + computerDeck);
document.getElementById("click").addEventListener("click", dealCards);
(function gameEnd () {
if (playerlife <=0 || computerLife <=0) {
alert('DONE');
}
}());
You should considering changing your code like this:
// new function
function checkIsGameOver () {
if (playerlife <=0 || computerLife <=0) {
alert('DONE');
}
}
function whoWon() {
var playerTopCard = getTopCard(playerDeck);
var computerTopCard = getTopCard(computerDeck);
if (playerTopCard > computerTopCard) {
console.log('Player Won! ' + playerTopCard + '/' + computerTopCard);
computerLife = computerLife - (playerTopCard - computerTopCard);
// added code here...
checkIsGameOver();
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
} else if (playerTopCard < computerTopCard) {
console.log('Computer Won! ' + playerTopCard + '/' + computerTopCard);
playerlife = playerlife - (computerTopCard - playerTopCard);
// added code here...
checkIsGameOver();
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
} else {
console.log('Tie! ' + playerTopCard + '/' + computerTopCard);
playerDeck.shift();
computerDeck.shift();
console.log('Player Life - ' + playerlife);
console.log('Computer Life - ' + computerLife);
}
}