0

How to display range, max and min of a random generated list of a 10 numbers?

let's say you get 10 random numbers whenever you click the button 4,32,79,9,55,45,20,34,12,61 And then it shows range: 50 largest number: 79 minimum number: 4 Thanks in advance

12th Nov 2017, 8:36 PM
Koddi
Koddi - avatar
7 Respostas
+ 2
You can make a placeholder for each of the. <p>range: <span id=:"range-result"></span></p> then to use getElementById("range") and to set its value to the computed value of range, and so on with the others..
12th Nov 2017, 10:24 PM
Uria
+ 2
Something like this should do: var arr = []; while (arr.length < 10){ arr.push(Math.floor(Math.random()*101)) } console.log(...arr); console.log(); console.log(Math.max(...arr)); console.log(); console.log(Math.min(...arr)); console.log(); console.log((Math.max(...arr) + Math.min(...arr)) / 2); --------------------------------------------- Not sure why you have range=50 though.....
12th Nov 2017, 9:22 PM
Uria
+ 1
happy it helps, pls note that here you have between 0-100
12th Nov 2017, 9:35 PM
Uria
+ 1
Read this one: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min Probably the best place to learn what you miss with JS. btw "..." is a new operator of ES6. You can also read about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
12th Nov 2017, 10:56 PM
Uria
0
Thank you. It's a random range! How to do it with the document.getElementById () etc ? I want the following to be printed on the screen range: 50 largest number: 79 minimum number: 4 Finishing the follow html code that is assigned in javascript <button id="btnRandom"></button> <p id="txt" > result </p> thank you
12th Nov 2017, 9:41 PM
Koddi
Koddi - avatar
0
That's what I thought about, but I'm not sure about the Math.min and so on Thank you, I appreciate your help.
12th Nov 2017, 10:26 PM
Koddi
Koddi - avatar
0
Thank you :)
12th Nov 2017, 11:05 PM
Koddi
Koddi - avatar