Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuis Rabines
20,308 Pointsquestion about random number with javascript
how to make 6 random numbers instead of just one using javascript?
function getRandomNumber(lower, upper){
if (isNaN(lower) || isNaN(upper) ){ throw new Error('something'); } return Math.floor(Math.random() * (upper - lower + 1)) + lower; }
console.log( getRandomNumber(1,6)); console.log( getRandomNumber('nine',6)); console.log( getRandomNumber('ten','elevent'));
1 Answer
Steven Parker
231,275 PointsAt the risk of being called Captain Obvious, how about calling the function you already have 6 times?
var randoms = [];
for (var i=0; i<6; i++) {
randoms.push(getRandomNumber(1,10));
}
console.log(randoms);
Luis Rabines
20,308 PointsLuis Rabines
20,308 Pointsmaybe I wrote the question wrong. My question is how can I get 6 random numbers at the same time, in other words each time I reload the browser I want to get 6 random characters. hopefully this makes explanation make sense.