0

奇妙なことに、構文エラーが表示されません。私はJavaScriptも初めてですが、決して無能ではありません。しかし、コードを実行するときはいつでも、使用するブラウザーでコード全体を実行せずに空白の Web ページに出力するだけです。以前にこの問題が発生したことはありません。コードが実行されていないため、ブラウザーのデバッグツールを使用できません。

いつものようにコードを適切に開始していないわけではありません

<html>
<body>
<script type="text/javascript">

その後に私のコードが続き、タグを閉じます

上記のコードがWebページに印刷されているため、最初からjavascriptとして認識されないのは奇妙なことです

誰かが以前にこの問題を抱えていましたか? 何か足りない?

<html>
<body>
<script type="text/javascript">

var die1;           // the 3 dice
var die2;
var die3;

var username;   // users name

var bet  = 0;            // variable for the amount the user bets
var input;              // used to check the bet is a number

var credits = 100;          // users overall credits and starting amount
var round = 0;          // game rounds , will have a maximum of 10 rounds


username = window.prompt("Welcome to Triple Roll! Please enter your name");     // prompts                  the user to enter their name
gamestart;                      // calls the first function to start the game!




var rolldice = function()       // puts all 3 dice rolls into a function to be easily called.
{
die1 = Math.round(Math.random()*6);         // random number generators for the 3 dice
die2 = Math.round(Math.random()*6);         // dieX is an integer (round number) in the  range of 1 to 6
die3 = Math.round(Math.random()*6);
}


var gamestart = function()   // Using this function the game can be reset to starting values, The user is also asked if they would like to hear the rules
{
bet = 0;
credits = 100;
round = 0;

if (window.prompt("Hello" + username ", Do you wish to go over the the instructions?   Y/N ")) = "Yes" || "yes" || "y" || "Y"    // if the user says yes then show rules , else run the game
    { 
confirm(" This game has 10 rounds, at the beginning of the game you will start with 100 credits to bet with. For each round of the game you will bet on the outcome of 3 dice rolls each with numbers 1 through 6. continue?");
confirm(" For each round you may bet between 1 and 100 credits regardless of how many credits you actually have, though be warned if you lose and end up with 0 credits then its game over.");
confirm(" The value of all 3 dice will determine whether or not you win or lose credits, but don't worry , you will be able to see how many credits you have at any time");
confirm(" If the 3 die all show a 1 , then you will win 50 times your bet plus the original stake back, If the 3 die all show the same value other than 1 then you win 30 times your bet plus your original stake back");
confirm("If 2 die show the same value, then you win 8 times your bet plus your original bet. If you don't meet any of the requirements but the values of die add up to 15 or more, then you win 2 times your bet plus the original stake.");
confirm("If one of the die is a 6 or all 3 of the die are odd numbers, then you get your bet back and may try again. In all other situations you lose your bet");
    }
else 
    { 
game;   // call the game function 
    }

}

 var game = function()
{ 
input = window.prompt("Round" + round ". You have" + credits "credits. Please enter a bet between 0-100"); // shows the user what round it is, how many credits they have and asks them to make a bet
bet = parseInt(input);          // checks the input is a number

 if (bet != 0-100);         // if the bet isn't between 0-100
    { 
    game;               // restart the function
    }
else                        // else
    { 
    rolldice;           // call the roll dice function
    }

confirm(" The Die rolls are" + die1 + die2 + die3);     // let user know what the dice values are
    winoutcomes;                // call the function that checks to see if the user has won

}

4

2 に答える 2

0

ファイル名は「xxxxxx.js」です

「xxxxx.html」である必要があります

また、スペースを入れないこともおそらく良い考えです。

'Assignment 01.js' を 'Assignment01.html' に変更します。

ファイルの名前を変更します。

それが動作します。

あなたはちょうど私が見るいくつかのコードを投稿しました。閉じた script/body/html タグはありません

于 2013-10-25T16:17:30.427 に答える