Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write to a web page with an external javascript file
    primarykey
    data
    text
    <p>I'm trying to make a Rock Paper Scissors script print out onto the webpage it's loaded on but it doesn't seem to show up. The prompt comes up but the result that I want it to print out isn't working.</p> <p>HTML file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Minigames for All&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="style.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;h2 id="header"&gt;Welcome to Minigames for All.&lt;/h2&gt; &lt;hr&gt; &lt;script src="rps.js"&gt;&lt;/script&gt; &lt;hr&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="rps.html"&gt;Rock, Paper, Scissors&lt;/td&gt; &lt;td&gt;&lt;a href="random.html"&gt;Guess the Number&lt;/td&gt; &lt;td&gt;&lt;a href="ttt.html"&gt;Tic Tac Toe&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="flip.html"&gt;Flip a Coin&lt;/td&gt; &lt;td&gt;&lt;a href="rpg.html"&gt;Slime RPG&lt;/td&gt; &lt;td&gt;&lt;a href="shoot.html"&gt;Space Shooter&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; </code></pre> <p></p> <p>JS file:</p> <pre><code>var userChoice = prompt("Do you choose rock, paper or scissors?"); userChoice=userChoice.toLower(); var computerChoice = Math.random(); if (computerChoice &lt; 0.34) { computerChoice = "rock"; } else if(computerChoice &lt;= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } var compare = function (choice1, choice2) { if(choice1 === choice2) { document.write ("The result is a tie!"); } if(choice1 === "rock") { if(choice2 === "scissors") { document.write ("Computer chose scissors. Rock wins"); } else { document.write ("Computer chose paper. Paper wins"); } } if(choice1 === "paper") { if(choice2 === "scissors") { document.write ("Computer chose scissors. Scissors wins"); } else { document.write ("Computer chose rock. Paper wins"); } } if(choice1 === "scissors") { if(choice2 === "paper") { document.write ("Computer chose paper. Scissors wins"); } else { document.write ("Computer chose scissors. Rock wins"); } } }; compare(userChoice, computerChoice); </code></pre> <p>Any idea how to make this show up? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload