誰でも私を助けることができますか?目的を持った「運ゲー」のスクリプトを書いています
ユーザーが希望する任意の数値を入力し、0 から入力した数値までの乱数を生成して結果配列に表示します。
「Heads or Tails」のゲームをシミュレートし、同じ結果配列になる結果も表示します (連想配列を使用します)
上記の 2 つの目標を合計 6 回実行します。
結果を表に表示します。
「表」の合計金額と「裏」の合計金額をそれぞれ合計して表示します。
6 つの結果から最小の数値を返します。
項目 1、2、および 3 はすでに完了しています。項目 6 のヘルプが必要です。2x7 の表に「コイン サイド」と「数字」という見出しを付けて結果を表示する方法と、すべての項目を合計する方法6回の試行の「頭」と「尾」、また生成された最小数を返しますか?
<body>
<div id = "luckGame"></div>
var userInput = prompt("Enter maximum number output: ");
printThis = document.getElementById('luckGame');
function coinFlip() {
return (Math.floor(Math.random() < 2) === 0) ? 'Heads' ; 'Tails';
}
for (var i = 0; i < 6; i++)
{
var result = [];
result["randomNum"] = (Math.floor(Math.random()*userInput);
result["coin"] = (coinFlip());
printThis.innerHTML = result["coin"] + " " + result["randomNum"];
//This loop will run 6 times.
//This should print for example: Heads 29 but I need to put all the results
//in a 2x7 table with labels "Coin Side" and "Number" included. How do I do this?
}
//Code here needed to sum total of 'Heads' and 'Tails'
//Code here needed to return the smallest number from the results.
</body>
テーブルの私のCSS
.results {
border: 1px solid black;
width: 200px;
height: 20px;
}
私のラフテーブル
var resultsTable = "<table class= 'results'><tr><td>" + "Coin Side" + "</td><td>" + "Number" + "</td></tr>";
resultsTable += "<tr><td> + result["coin"] + "</td><td> + result["randomNum"] + </td></tr>";
... // repeat 4 more times.
resultsTable += "<tr><td> + result["coin"] + "</td><td> + result["randomNum"] + </td></tr></table>;
詳細を記載する必要がある場合は、お知らせください。