Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!