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

312
Vistas
cómo usar un si es igual a falso con una cadena asignada a un número

Así que estoy tratando de hacer que mi código se ejecute nuevamente si asigna undefined como lo que estoy imprimiendo en mi consola, básicamente tengo una matriz completa que se somete a una matemática. para asignar cada parte diferente de la matriz a un número, pero a veces aparece como indefinido, así que intenté arreglar eso con un Number.isInteger, así como un If false. Básicamente, Number.isInteger está redefiniendo mi matriz si no es un número falso y luego la declaración If maneja el resto, pero no funciona como pensé que lo haría.

 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

Está utilizando el operador de asignación para el caso if. Necesita que el operador de igualdad use == o === allí.

Así es como debería ser:

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

Tal vez esto es lo que estás buscando:

 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