본문 바로가기

잼있냐JavaScript

로또 번호

1. How much money you need ?

Have you ever buy lotto?

but you have to write six number

So you can get number easliy!!!

just Click!! Button

i wish You will Have Luck number!! go ! go!






-- 소스 --

<script language="javascript">
 ar1 = new Array(6);

 function makeRandom(n){
  var r = 0;
  m = 1
 
 
  r = Math.round(Math.random()*n) + m;
  return r;
 
 }
 
 function makeRottoNum(){
   var s
   for(i=0;i<ar1.length;i++){
     s = makeRandom(100);
     s = ((s>45) ? s-(s-45) : s);
     ar1[i] = s
   }
  
 }
 
 function validateNum(){
   var c=0;
   for(i=0 ; i<ar1.length-1 ; i++){
                                     
      for(j=i+1; j<ar1.length;j++){
                  if(ar1[i] == ar1[j]){
                          // 로또를 다시 만들어야 하는가?
                          c++;     
                  } 
      }
   }
   if(c>0){
     return true;
   }else{
     return false;
   }
 
 }
 
 
 function insertNum(){
   
    var wd = window.document.roform;
   
    wd.t0.value=ar1[0];
   
    wd.t1.value=ar1[1];
   
    wd.t2.value=ar1[2];
   
    wd.t3.value=ar1[3];
   
    wd.t4.value=ar1[4];
   
    wd.t5.value=ar1[5];
   
 
 }
 
 function finishNum(){
     var flag = true;
     while(flag){
         makeRottoNum();
         flag = validateNum();
     }
     insertNum();
 }
</script>

'잼있냐JavaScript' 카테고리의 다른 글

javascript - replace("find","replacestr")  (0) 2008.11.07
야구게임  (0) 2008.10.22
시를 출력해주는 클래스  (0) 2008.10.22
Color Table  (0) 2008.10.22
Magic Number  (0) 2008.10.22