Reputation: 11
So I set this up for a bit of simple math to add a little flair to a madlibs game. Yet everytime I run this I get a decimal answer rather than a whole number, Math.round(x, n) doesn't work either. Is there some improper syntax or something I'm missing?
let height = prompt("About how tall are you like inch-wise? 48 = 4 feet, 60 = 5 feet , 72 = 6 feet."); //for height multiple in story
if (isNaN(height)) {
height = 66;
}
else {
height = height;
};
height = height / 12;
console.log(height);
Math.round(height);
console.log(height);
Upvotes: 0
Views: 35
Reputation: 190897
JavaScript doesn't pass variables by reference and Math.round
returns the rounded value. So you have to assign the resulting value.
height = Math.round(height);
Upvotes: 4