0
function flipCoin1() {
  console.log("flipCoin", Math.random < 0.5);
}
flipCoin1();
// OP : always returns false

function flipCoin2() {
  let a = Math.random();
  console.log("flipCoin1", a < 0.5);
}
flipCoin2();
// OP : returns true and false randomly

flipCoin1 function always returns false, while flipCoin2 works properly returning true and false randomly?

VLAZ
  • 26,331
  • 9
  • 49
  • 67

1 Answers1

0

You are comparing the function itself in the first function. You need to call it.

function flipCoin1() {
  console.log("flipCoin", Math.random() < 0.5);
}
Maheer Ali
  • 35,834
  • 5
  • 42
  • 73