0

The If always gives me the last result

check this snippet

function calc(on, ep, am, ek, b1, b2, b3, b4) {
  var sum, mo;
  b1 = parseInt(b1);
  b2 = parseInt(b2);
  b3 = parseInt(b3);
  b4 = parseInt(b4);
  sum = b1 + b2 + b3 + b4;
  mo = sum / 4;
  if (mo < 5) {
    x = "Not Good";
  }
  if (mo < 6, 5 && mo > 4, 99) {
    x = "Good";
  }
  if (mo < 8, 5 && mo > 6, 49) {
    x = "Really Good";
  }
  if (mo > 8, 49) {
    x = "Perfect";
  }
  alert("O " + on + " " + ep + " " + am + " who is in " + ek + "th semester had avereged " + mo + " " + x);
}
I cant get it to work with else if or something like that but I need it to work however it is
Geeky
  • 7,420
  • 2
  • 24
  • 50
  • [Don't use parseInt without a radix](http://stackoverflow.com/questions/6611824/why-do-we-need-to-use-radix). – Quentin Jan 11 '17 at 18:34

2 Answers2

5

JavaScript floating point literals use a . character (U+002E : FULL STOP) as a decimal point, not a , character (U+002C : COMMA) (which is a comma operator).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

As already said you have to use . and not ,. Your mo < 6,5 && mo > 4,99 will always evaluate to 99 which is truthy. So it does not matter what value the mo has.

var mo = 10;
console.log( (mo < 6,5 && mo > 4,99) );

See MDN: Comma operator for more informations:

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

t.niese
  • 39,256
  • 9
  • 74
  • 101