そこで、HTML/CSS/JavaScript の学習を開始し、じゃんけんの非常に単純なバージョンを作成しようとしているときに、この問題に遭遇しました。コードは正常に動作すると思いますが、実行を拒否しているため確認できません。私はインターネットで答えを広範囲に探しましたが、何も見つからないようです。私は JavaScript の経験がほとんどなく、現在Codecademyから学んでいますが、他の Web サイトの構文が競合しているように見えるため、リソースが古くなっている可能性があると思います。要するに、私は何を間違っているのでしょうか? どの Web サイトが正しいのでしょうか?
<html>
<head>
<title>R,P,S!</title>
<script type="text/javascript">
function whole(){
function game(play){
if (play="yes"){
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";}
else if(computerChoice <= 0.67) {
computerChoice = "paper";}
else {
computerChoice = "scissors";
}
function compare(choice1,choice2){
if (choice1==choice2){
compare(userChoice,computerChoice);
}
if (choice1=="rock"){
if (choice2=="scissors"){
document.getElementById("result").innerHTML="Rock wins";
}
else{
document.getElementById("result").innerHTML="Paper wins";
}
}
if (choice1=="paper"){
if (choice2=="rock"){
document.getElementById("result").innerHTML="Paper wins";
}
else{
document.getElementById("result").innerHTML="Scissors win";
}
}
if (choice1=="scissors"){
if (choice2=="paper"){
document.getElementById("result").innerHTML="Scissors win";
}
else{
document.getElementById("result").innerHTML="Rock wins";
}
}
};
compare(userChoice,computerChoice);
}
else{
document.writeln("<p>Thanks for playing! This was made by Alex</p>";)
}
}
var start = prompt ("Do you want to play?","Yes");}
</script>
</head>
<body style="text-align:center">
<h1>JavaScript on a webpage? This is madness!</h1>
<h2>Madness? THIS... IS... HTML!!!!</h2>
<button onclick="whole()">Try it out!</button>
<p id="result">Who won?</p>
</body>
</html>
**編集: Codecademy の用語集は他の Web サイトと一致しているようですが、彼らはまだレッスンの編集に取り掛かっていません.*
**編集:これが私の最後の小さなコードです。そのシンプルさをお楽しみください!*
<html>
<head>
<title>R,P,S!</title>
<script type="text/javascript">
function whole(){
function game(play){
if (play=="Yes"||play=="yes"){
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";}
else if(computerChoice <= 0.67) {
computerChoice = "paper";}
else {
computerChoice = "scissors";
}
function compare(choice1,choice2){
if (choice1==choice2){
alert("It was a tie!");
game("yes");
}
if (choice1=="rock"){
if (choice2=="scissors"){
document.getElementById("messages").innerHTML="";
document.getElementById("win").innerHTML="You win. Rock crushes scissors.";
document.getElementById("loss").innerHTML="";
}
else{
document.getElementById("messages").innerHTML="";
document.getElementById("loss").innerHTML="You lose. Paper smothers rock.";
document.getElementById("win").innerHTML="";
}
}
else if (choice1=="paper"){
if (choice2=="rock"){
document.getElementById("messages").innerHTML="";
document.getElementById("win").innerHTML="You win. Paper smothers rock.";
document.getElementById("loss").innerHTML="";
}
else{
document.getElementById("messages").innerHTML="";
document.getElementById("loss").innerHTML="You lose. Scissors cut paper.";
document.getElementById("win").innerHTML="";
}
}
else if (choice1=="scissors"){
if (choice2=="paper"){
document.getElementById("messages").innerHTML="";
document.getElementById("win").innerHTML="You win. Scissors cut paper.";
document.getElementById("loss").innerHTML="";
}
else{
document.getElementById("messages").innerHTML="";
document.getElementById("loss").innerHTML="You lose. Rock crushes scissors.";
document.getElementById("win").innerHTML="";
}
}
else{
alert("Very funny. Now do it right.");
game("yes");
}
};
compare(userChoice,computerChoice);
}
else{
document.getElementById("messages").innerHTML="Well alrighty then.";
document.getElementById("loss").innerHTML="";
document.getElementById("win").innerHTML="";
}
}
var start = prompt ("Do you want to play?","Yes");
game(start);}
</script>
<style>
body{
text-align:center;
}
#messages{
font-size:20px;
color: #00246B;
}
#win{
color: #29A329;
font-size:18px;
}
#loss{
color:#CC0000;
font-size:18px;
}
a{
text-decoration:none;
color:black;
}
a:hover{
font-size:125%;
color:#B20000;
}
button{
font-size:21px;
}
</style>
</head>
<body>
<a href="http://youtu.be/T8r3cWM4JII">
<h1>JavaScript on a webpage? This is madness!</h1>
<h2>Madness? THIS... IS... HTML!!!!</h2>
</a>
<button onclick="whole()">Try it out!</button>
<p id="messages">Who won?</p>
<p class="result"><span id="loss"></span><span id="win"></span></p>
</body>
</html>