実現したいこと
Javascriptにて、乱数で0~2の整数を10×4のテーブル表に入れていき、格納された数字が4つとも同じ行があればその行の数字を青で表示したいです。
発生している問題
テーブル表は出来たのですが同じ行の数字がすべて同一でもその数字たちが青で表示されずに困っております
該当のソースコード
Javascript
1<script type="text/javascript"> 2 3 document.write("<h3>4×10テーブル</h3>"); 4 document.write("<table border>"); 5 6 for (var i = 1; i <= 10; i++) { 7 8 document.write("<tr>"); 9 10 var a=Math.floor (Math.random ( ) * 3); 11 document.write("<td>",a,"</td>"); 12 var b=Math.floor (Math.random ( ) * 3); 13 document.write("<td>",b,"</td>"); 14 var c=Math.floor (Math.random ( ) * 3); 15 document.write("<td>",c,"</td>"); 16 var d=Math.floor (Math.random ( ) * 3); 17 document.write("<td>",d,"</td>"); 18<!--Math.floor (Math.random ( ) * 3);で0 or 1 or 2の乱数を生成--> 19if(a==b && a==c && a==d){ 20a.style.color="blue"; 21b.style.color="blue"; 22c.style.color="blue"; 23d.style.color="blue"; 24} 25 26 document.write("</tr>"); 27 28 } 29 30 document.write("</table>"); 31 32</script>
現状の実行結果
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/30 04:55