2013年6月30日日曜日

Loto6 プログラム

出力はこちらです====================




===================================
javascript を勉強します。はじめに作成したプログラムは 1から43までのランダム
数字を出力します。 数字は重複しないこと、数字をソートすること。
又、1と43は出なければならない。 リフレッシュして、結果が変更されます。バグが
ありましたら、お知らせください。

Loto6ですね。


var loto6 = new Array ();
do{
var x= Math.round(Math.random() *42+1);
document.write(x + ',');
if (loto6.indexOf(x)>-1){
continue;
}
loto6.push(x);
}while(loto6.length<6);
document.write('<br>');
document.write(loto6);
document.write('<br>');

var sortfun = function(a,b){
    if( a < b ) return -1;
        if( a > b ) return 1;
        if( a == b ) return 0;

}


var x=loto6.sort(sortfun);
document.write(x);

0 件のコメント: