0
#!/bin/sh

//Rock, Paper, Scissors

var myChoice = prompt("Rock, Paper, or Scissors?");

var computerChoice = Math.random();

if (computerChoice >= 0 && computerChoice <= .33) 
{
    computerChoice === "rock";
}
else if (computerChoice >=.34 && computerChoice <= .67) 
{
    computerChoice === "paper";
}
else 
{
    computerChoice === "scissors";
};

I understand my code to be rudimentary, but I am just beginning with Javacript. I am trying to run this code through the terminal and continue to get the error message "can't find variable: prompt." I am sure there is a simple explanation out there, but I can't seem to find it.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49

2 Answers2

0

prompt() is for browsers. You should use the functions found here instead.

grc
  • 22,885
  • 5
  • 42
  • 63
0

You cannot use the prompt function in terminal. It only works in browsers, as it causes a box to popup that the user enters something in. Put it in an html file, and it will work:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        // your code goes here, minus that first comment.
        </script>
    </head>
</html>
markasoftware
  • 12,292
  • 8
  • 41
  • 69