Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

321
Vistas
how to use an if equals false with a number assigned string

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);
};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are using the assignment operator for the if case. You need the equality operator either use == or === there.

This is how it should be:

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);
};

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda