현재 자바 스크립트를 배우려고하는데 어려움을 겪고 있습니다.js 파일의 HTML 출력
사용자에게 약간의 출력을 제공해야하는 작은 바위 종이 가위 스크립트를 작성했지만 실제 출력을 얻을 수없는 것 같습니다.
JS 스크립트는 다음과 같다 :
var computerChoiceLine = 0
var tieResult = "The result is a tie!";
var winResult = "You won!";
var lossResult = "You lost..."
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
// convert computerChoice into text
if (computerChoice <= 0.34) {
computerChoiceLine = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
// convert userChoice into number
if (userChoice == "rock") {
userChoiceNumber = 0;
} else if(userChoice == "paper") {
userChoiceNumber = 0.50;
} else if(userChoice == "scissors"){
userChoiceNumber = 1;
} else {
userChoiceNumber = 100;
}
var output = function(choice1, choice2){
document.write("You chose " + choice1)
document.write("\n The computer chose " + choice2)
compare(userChoiceNumber , computerChoice)
var compare = function(choice1 , choice2){
if(choice1 == choice2){
document.write(tieResult);
}
if(choice1 < choice2){
document.write(lossResult);
}
if(choice1 > choice2){
document.write(winResult);
}
};
if(userChoice == 100){
document.write("Please type rock, paper or scissors")
} else {
output(userChoice , computerChoiceLine);
};
}
그리고는 다음과 같이 HTML에 대한 전화 :
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript" src="RockPaperScissors.js"></script>
</body>
</html>
사람이 내가 잘못하고있는 중이 설명해 주시겠습니까, 내가 어떻게 변경해야 그것?
어떤 오류가 발생합니까? – putvande
실제로 그것을 정의하기 전에'compare'를 호출하십시오. 'tieResult'의 결과를 놓치십니까? – thriqon
내가 알기로, 나는 그것을 호출하기 전에 compare를 정의했다. 그리고 오류가 발생하지 않고 빈 웹 페이지가 생기고 프롬프트가 나타나지만 페이지가 비어 있습니다. – gooper20