0
i dont want that there comes the same numbers at the same time
what i have to add, what is the best ? need some help here can you find my code https://code.sololearn.com/W9165KUpI99P/#html
9 Respuestas
+ 1
Use for loop
generate random number
check if it is already generated
if yes generate another number
+ 1
You need to add function to do checking and ensure unique result.
I modified your update of "number" array
using below statement:
number[0] = (()=>{ do{ n = Math.floor((Math.random() * 50) + 1)}while(number.includes(n)); return n;})();
Check out the modified code here:
https://code.sololearn.com/WTLHrM42d9Ld/?ref=app
+ 1
function getSortNumbers()
{
var num = new Array();
for(var i=0; i<7; i++)
{
ran=0;
while(true)
{
ran= Math.floor((Math.random() *50) +1);
if(num.includes(ran))
continue;
else
break;
}
num.push(ran);
}
return num;
}
0
https://code.sololearn.com/WWJz5u7gctiU/?ref=app
This might helps you.
0
doesnt work by me ^^
0
What do you mean by
"i dont want that there comes the same numbers at the same time"?
0
@Wondwosen Abebaw how? im not so far :/
0
@calvin
like and not
1 2
2 2
3 3
4 3
6 5
7 7
0
@Calvin Thank you so much, i kiss your eyes Bro