So im trying to make my code run again if it assigns undefined as what im printing to my console, basically I have an entire array put through a math. to assign each different part of the array to a number, but sometimes it comes through as undefined so i tried fixing that with an Number.isInteger, aswell as an If false. Basically Number.isInteger is redefining my array if its not a number to false and then the If statement handles the rest, yet its not working how i thought it would.
var name = new Array("bloods edge", "grass cutter", "death bringer", "yellow harbinger", "flame cutter", "ice shooter", "Big Hurt", "gun", "big gun", "bigger gun", "biggg gun", "biggest gun", "big sword", "sword", "bigger sword", "big swords brother");
var name = name[Math.floor(Math.random() * 17)];
var name = name[Number.isInteger];
console.log(name);
if (name = false) {
var name = new Array("bloods edge", "grass cutter", "death bringer", "yellow harbinger", "flame cutter", "ice shooter", "Big Hurt", "gun", "big gun", "bigger gun", "biggg gun", "biggest gun", "big sword", "sword", "bigger sword", "big swords brother");
var name = name[Math.floor(Math.random() * 17)];
console.log(name);
console.log("Attack Damage");
};
console.log(name);
console.log("Attack Damage");
const Damage = (Math.random() * 100);
console.log(Math.ceil(Damage));
var prefix = new Array("Swings with a burst of fire!", "Inflicts Posion!", "A very sharp boy", "Shoots discs of mana", "Sometimes kills instantly", "Sometimes heals you to max health");
var prefix = prefix[Math.floor(Math.random() * 6)];
if (Damage >= 70) {
console.log("PREFIX FOR BEING GOD WOW!");
console.log(prefix);
};
var badPrefix = new Array("broken to bits", "sometimes inflicts no damage", "inflicts self damage", "why would you use this???", "seriously stop using me", "Insults you everytime you swing", "just rude");
var badPrefix = badPrefix[Math.floor(Math.random() * 7)];
if (Damage <= 30) {
console.log("Prefix for being BAD");
console.log(badPrefix);
};
You are using the assignment operator for the if case. You need the equality operator either use == or === there.
if (name === false) {
var name = new Array("bloods edge", "grass cutter", "death bringer", "yellow harbinger", "flame cutter", "ice shooter", "Big Hurt", "gun", "big gun", "bigger gun", "biggg gun", "biggest gun", "big sword", "sword", "bigger sword", "big swords brother");
var name = name[Math.floor(Math.random() * 17)];
console.log(name);
console.log("Attack Damage");
};
Maybe this is what you are looking for:
var name = ["bloods edge", "grass cutter", "death bringer", "yellow harbinger", "flame cutter", "ice shooter", "Big Hurt", "gun", "big gun", "bigger gun", "biggg gun", "biggest gun", "big sword", "sword", "bigger sword", "big swords brother"];
let randomNum=Math.floor(Math.random() * 17)
var name = name[randomNum];
//var name = name[Number.isInteger];
console.log(name);
if (name === false) {
var name = ["bloods edge", "grass cutter", "death bringer", "yellow harbinger", "flame cutter", "ice shooter", "Big Hurt", "gun", "big gun", "bigger gun", "biggg gun", "biggest gun", "big sword", "sword", "bigger sword", "big swords brother"];
var name = name[Math.floor(Math.random() * 17)];
console.log(name);
console.log("Attack Damage");
};
console.log(name);
console.log("Attack Damage");
const Damage = (Math.random() * 100);
console.log(Math.ceil(Damage));
var prefix = new Array("Swings with a burst of fire!", "Inflicts Posion!", "A very sharp boy", "Shoots discs of mana", "Sometimes kills instantly", "Sometimes heals you to max health");
var prefix = prefix[Math.floor(Math.random() * 6)];
if (Damage >= 70) {
console.log("PREFIX FOR BEING GOD WOW!");
console.log(prefix);
};
var badPrefix = new Array("broken to bits", "sometimes inflicts no damage", "inflicts self damage", "why would you use this???", "seriously stop using me", "Insults you everytime you swing", "just rude");
var badPrefix = badPrefix[Math.floor(Math.random() * 7)];
if (Damage <= 30) {
console.log("Prefix for being BAD");
console.log(badPrefix);
};