Need help for a game inventory system i'm making

javascript

#1

I am making a game for school and I am having trouble with the inventory system. I'll post the inventory code down below. thanks in advance.

//inventory variables
var baseDefense = 10;
var baseAttack = 10;
var baseHealth = 10;
var attack = baseAttack;
var defense = baseDefense;
var health = baseHealth;
//inventory variables
var woodBoots = ["woodBoots", WoodBoots]; //health, attack, defense
var WoodBoots = [10, 10, 10];
var ironSword = ["ironSword", IronSword];
var IronSword = [0, 10, 0];
var woodSword = ["woodSword", WoodSword];
var WoodSword = [0, 5, 0];
var inventory = [woodBoots, ironSword, woodSword];

var numItems = [];
var name;
var item = 0;
var equipment = [IronSword];

//code
var inventoryOpen = function() {
while (item < inventory.length) {
name = item + ". " + inventory[item][0] + " ";
numItems = numItems + name;
item = item + 1;
}
var select = prompt("you have " + numItems + "type the number of the item you wish to select, type back to go back");
if(select != "back") {
var equip = prompt("do you want to equip this weapon(yes or no)").toLowerCase();
if(equip == "yes") {
equipment = equipment + inventory[select][1];
closeEquipment();
} else {
inventoryOpen();
}
} else {
closeEquipment();
menu();
}
};

//close equipment menu and update stats
var closeEquipment = function() {
//equipment variables
var i = 0;
//code
while(i < equipment.length) {
var check;
check = equipment[i];
health = health + check[0];
attack = attack + check[1];
defense = defense + check[2];
i = i + 1;
}
console.log("attack " + attack);
console.log("health " + health);
console.log("defense " + defense);
};

inventoryOpen();


#2

@awsomedestroyers,

var baseDefense = 10;
var baseAttack = 10;
var baseHealth = 10;
var attack = baseAttack;
var defense = baseDefense;
var health = baseHealth;
//inventory variables
var WoodBoots = [10, 10, 10];
var woodBoots = ["woodBoots", WoodBoots]; //health, attack, defense
var IronSword = [0, 10, 0];
var ironSword = ["ironSword", IronSword];
var WoodSword = [0, 5, 0];
var woodSword = ["woodSword", WoodSword];
var inventory = [woodBoots, ironSword, woodSword];

var numItems = [];
 var name;
var item = 0;
var equipment;
var equipmentName;
var equip;
console.log("0a==> "+equipment);
console.log("0b==> "+inventory);

//code

var inventoryOpen = function() {
 while (item < inventory.length) {
     name = item + ". " + inventory[item][0] + " ";
     numItems = numItems + name;
     item = item + 1;
 }
 console.log(name);
 console.log(numItems);
 var select = prompt(
    "you have " + numItems + 
    "type the number of the item you wish to select, "+
    "type back to go back");
 if(select != "back") {
     var equip = prompt(
         "do you want to equip this weapon(yes or no)").toLowerCase();
     if(equip == "yes") {
         console.log("2==> "+equipment);
         equipment = inventory[select][1];
         console.log("3a==> "+equipment);
         equipmentName= inventory[select][0];
         console.log("3b==> "+equipmentName);
         closeEquipment();
     } else {
         inventoryOpen();
     }
 } else {
     closeEquipment();
     menu();
 }
};

//close equipment menu and update stats

var closeEquipment = function() {
    //equipment variables
    //var i = 0;
//code
    //var check; 
    //while(i < equipment.length) { 
    //   check = equipment[i]; 
       console.log("4a ==> "+equipmentName);
       health = health + equipment[0]; 
       attack = attack + equipment[1]; 
       defense = defense + equipment[2]; 
    //   i = i + 1;
    //}
console.log("attack " + attack);
console.log("health " + health);
console.log("defense " + defense);
};

inventoryOpen();