Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda