javascript random number negative code example Example: math random from minus 1 var plusOrMinus = Math.random() < 0.5 ? -1 : 1;