I am trying to create an array of 6 unique random numbers out of an array that the user gave his max value and min value (no lower then 0 and no higher then 37). What is incorrect?
function randCalc(maxVal,minVal)
{
var maxVal = document.getElementById("maxRange").value;
var minVal = document.getElementById("minRange").value;
var tmpArray = new Array(6) ;
tmpArray = [0];
var realArray = new Array(6);
realArray = tmpArray;
if ((maxVal - minVal) < 6)
{
alert("</br>The difference cannot be lower then 6");
}
if (minVal<1)
{
alert("</br>The min value cannot be lower then 1");
}
if (maxVal>37)
{
throw alert("</br>The higher value cannot be higher then 37") ;
}
if(minVal>0 && ((maxVal-minVal)>=6)&& (maxVal<=37) )
{
document.writeln("</br>The random numbers are: ");
for(i=0;i<=(6);i++)
{
var randLotto = Math.floor(Math.random() * (maxVal - minVal + 2) + minVal);
tmpArray[i] = randLotto;
}
for(var j=0;j<=maxVal;j++)
{
for(var k=0;k<6;k++)
{
if(tmpArray[j]==realArray[k])
{
j++;
}
else if(tmpArray[j]!=realArray[k])
{
realArray[k]=tmpArray[j];
}
}
if(realArray[6]!=null)
{
break;
}
}
}
}
Any idea how to make it work?
` or `
` (though that's just a simple syntax error, and almost certainly *not* your actual problem).. – David Thomas Mar 14 '14 at 08:33