HTML, CSS, JS if statement thinks 1==0
17:26 07 May 2017

This is a card game I am making. The codepen is at LINK

The problem is that the code is only supposed to delete cards with 0 health but it is instead, deleting cards with all health levels. In the battle function, you will see the if statement I am referring to. I am checking if a number from an array is 0 but one of the cards has 1 health but It is being deleted too. To see the cards, comment out when the setup function is called.

var turn = true;

var enemyCards = document.getElementById('enemy-cards');

var friendlyCards = document.getElementById('friendly-cards');

var friendlyHealth = document.getElementById('friendly-health-value');

var enemyHealth = document.getElementById('enemy-health-value');

var enemyCardArray = [[2, 3], [2, 4]];

var friendlyCardArray = [[3, 3], [3,2]];

function initialSetup() {
  for (var i=0; i < enemyCardArray.length; i++) {
    var card = enemyCardArray[i]
    var damage = card[0];
    var health = card[1];
    enemyCards.innerHTML += "

"+damage+"

"+health+"

" } for (var i=0; i < friendlyCardArray.length; i++) { var card = friendlyCardArray[i] var damage = card[0]; var health = card[1]; friendlyCards.innerHTML += "

"+damage+"

"+health+"

" } } function setup() { enemyCards.innerHTML = "";//<--Set it to "" here, not in for loop friendlyCards.innerHTML = "";//<--Set it to "" here, not in for loop for (var i = 0; i < enemyCardArray.length; i++) { var card = enemyCardArray[i] var damage = card[0]; var health = card[1]; //enemyCards.innerHTML = ""; enemyCards.innerHTML += "

" + damage + "

" + health + "

"; } for (var i = 0; i < friendlyCardArray.length; i++) { var card = friendlyCardArray[i] var damage = card[0]; var health = card[1]; //friendlyCards.innerHTML = ""; friendlyCards.innerHTML += "

" + damage + "

" + health + "

"; } } function battle() { if (turn === true){ for (var i = 0; i
body {
  margin: 0;
  font-family: sans-serif;
  position: relative;
}

#enemy-cards{
  background-color: #873a00;
  width: 100%;
  height: 270px;
}

#friendly-cards{
  background-color: #873a00;
  width: 100%;
  height: 270px;
  position: fixed;
  bottom: 0;
}

.card {
  width: 150px;
  height: 250px;
  background-color: #afafaf;
  margin-top: 10px;
  margin-left: 10px;
  margin-bottom: 10px;
  position: relative;
  float:left;
}

.damage {
  text-align: left;
  position: absolute;
  bottom:0;
  left: 20px;
}

.health {
  text-align: right;
  position: absolute;
  bottom:0;
  right: 20px;
}

#friendly-health{
  float:left;
  width: 50%;
  background-color: lightgreen;
  height: 200px;
}
#friendly-health-value{
  position: fixed;
  left: 25%;
  vertical-align: middle;
  color: white;
}

#enemy-health-value{
  position: fixed;
  left: 75%;
  vertical-align: middle;
  color: white;
}

#enemy-health{
  float:left;
  width: 50%;
  background-color: #f73f27;
  height: 200px;
}

20

20

javascript html css math