vendredi 10 novembre 2017

JavaScript - Adding 2 integers simply doesn't do anything

When I try to add two integers together, the integer just stays at what it originally was. It's difficult to explain, so here's my code:

var levelRewardsID = parseInt(resultData[0].levelRewardsHighestID)
var levelRewardsIDIncrease = Math.floor(Math.random()*9)+1
var newLevelRewardsID = levelRewardsID+levelRewardsIDIncrease
console.log(colors.blue(levelRewardsID))
console.log(colors.blue(levelRewardsIDIncrease))
console.log(colors.blue(newLevelRewardsID))
if (!isNaN(levelRewardsID)) {
  console.log(colors.blue("not NAN"))
}
if (!isNaN(levelRewardsIDIncrease)) {
  console.log(colors.blue("not NAN 2"))
}
if (!isNaN(newLevelRewardsID)) {
   console.log(colors.blue("not NAN 3"))
}

Console:

89819672607051330000
6
89819672607051330000
not NAN
not NAN 2
not NAN 3

So as you can see, everything is an integer. So that can't be the issue. Yet when I try to do var newLevelRewardsID = levelRewardsID+levelRewardsIDIncrease, the output is the same as levelRewardsID... I'm not sure what I did wrong but if anyone knows, do let me know. Thanks!

Note: I'm using Node.JS version 9.1.0 (latest as of posting this) if that helps




Aucun commentaire:

Enregistrer un commentaire