- 1

How to generate either absolute value and non absolute random numbers in JS

With this code: function (min,max) {document.getElementById("num").innerHTML=Math.floor(Math.random*(max-min)+min;} With the HTML file already with "num" id it generate random positive number when the assigned button is clicked. when the (max-min) is replaced with(min-max) it will generate random negative number. I am asking how to make it show either negative or positive with one code without writing for negative and positive differently.

29th Jul 2020, 3:00 PM
Anyanwu Johnbosco Chima
Anyanwu Johnbosco Chima - avatar
1 Answer
0
Ok a little mistake in the code {....(Math.random()*......}
29th Jul 2020, 3:03 PM
Anyanwu Johnbosco Chima
Anyanwu Johnbosco Chima - avatar