2013-03-12 2 views
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"; 
}; 

본인의 코드가 초보자라는 것을 이해하지만 Javacript로 시작합니다. 터미널을 통해이 코드를 실행하려고 시도하고 "변수를 찾을 수 없습니다 : 프롬프트"라는 오류 메시지가 계속 나타납니다. 거기에 간단한 설명이있을 것이라고 확신하지만 그것을 찾을 수없는 것 같습니다.변수를 찾을 수 없음 : 프롬프트

+0

파일에 저장하려고하면 작동합니까? – Markasoftware

+2

'prompt()'는 브라우저 용입니다. 나는 당신이 [this] (http://stackoverflow.com/questions/3120761/how-do-i-get-console-input-in-javascript)를 찾고 있다고 생각한다. – grc

+0

충분하다. thanks – user2158974

답변

0

prompt()은 브라우저입니다. 대신 찾은 기능 here을 사용해야합니다.

0

터미널에서 프롬프트 기능을 사용할 수 없습니다. 그것은 사용자가 무언가를 입력 상자를 팝업으로 인해 브라우저에서 작동합니다. 그것은 작동합니다 :

<!DOCTYPE html> 
<html> 
    <head> 
     <script type="text/javascript"> 
     // your code goes here, minus that first comment. 
     </script> 
    </head> 
</html>