我已經存儲了兩個變量,它們會生成模擬兩個隨機擲骰的變量。我試圖將它們添加到另一段中,如下所示;但是,添加它們的線會生成「NaN」。有什麼建議麼?在JavaScript中添加兩個變量,其中包含HTML
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Rolling Two Dice</title>
</head>
<body>
<p>Your first die rolled a <script>var roll1 = document.write(1 +
Math.floor(6 * Math.random()))</script>.</p>
<p>Your second die rolled a <script>var roll2 = document.write(1 +
Math.floor(6 * Math.random()))</script>.</p>
<p>The total of your rolls is <script>document.write(roll1 +roll2)</script>.</p>
</body>
</html>