2016-09-25 21 views
-2

誰かがこれで私を助けることができます。ここでは、私はユーザーから取得する文字列として3つの異なる数字のセットを持っており、私はまた、私はユーザーから取得する数字のセットと比較したい別の3つのランダムに生成された数字を持っている私はそれらを変換する理由を見ていない番号に任意の計算はので、私は、あなたがすべきlocaleCompare()関数をJavaScriptで文字列を比較するために、文字列ここに私のコードの何が間違っています

function radGenerator(userno1,userno2,userno3,wnum1, wnum2, wnum3,dvresult) { 
    $(wnum1).text("" + Math.floor((Math.random() * 10) + 1)); 
    $(wnum2).text("" + Math.floor((Math.random() * 10) + 1)); 
    $(wnum3).text("" + Math.floor((Math.random() * 10) + 1)); 

    var num1 = num2 = num3 = ""; 
    if($(userno1).text()== $(wnum1).text()|| 
    $(userno1).text()== $(wnum2).text()|| 
    $(userno1).text()== $(wnum3).text()){ 
    num1 = $(userno1).text(); 
    } 
    if($(userno2).text()== $(wnum1).text()|| 
    $(userno2).text()== $(wnum2).text()|| 
    $(userno2).text()== $(wnum3).text()){ 
    num2 = $(userno2).text(); 
    } 

    if($(userno3).text()== $(wnum1).text()|| 
    $(userno3).text()== $(wnum2).text()|| 
    $(userno3).text()== $(wnum3).text()){ 
    num3 = $(userno3).text(); 
    } 

    $(dvresult).text("Winning Numbers: " + num1 +" "+ " "+ num2 + " "+ num3); 

} 
radGenerator("#uans1","#uans2","#uans3","#wno1", "#wno2", "#wno3","#divresult"); 
+1

あなたが尋ねていることをよりわかりやすいタイトルで伝えてください –

答えて

0

としてそれらを比較しようとしています。 "string".localeCompare("otherString");は "string"が "otherString"の後に来るため1を返します。等しい場合は0を返し、比較している文字列の前に最初の文字列がある場合は-1を返します。

関連する問題