How to generate either absolute value and non absolute random numbers in JS | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
- 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 ответ
0
Ok a little mistake in the code {....(Math.random()*......}
29th Jul 2020, 3:03 PM
Anyanwu Johnbosco Chima
Anyanwu Johnbosco Chima - avatar