0
別のnoob javascriptの質問はこちら。私は次のコードを持っていますが、私は、 "忘れてしまった"と "スコア"を追加する方法が好きです。勝利には「III」、敗者には「IIII」となります)。どのようにこの最高のjavascriptで行うことができますか?Javascriptでウェブページを追加する方法
<html>
<head>
<title>Sarah's Card Game</title>
<script type="text/javascript">
Array.prototype.shuffle = function() {
var len = this.length;
var i = len;
while (i--) {
var p = parseInt(Math.random()*len);
var t = this[i];
this[i] = this[p];
this[p] = t;
}
};
</script>
</head>
<body>
<body onLoad="number=0"></p>
<p>This is the fun card game, a number will appear, afterwards, guess the card below which matches the number shown!</p>
<div id="click"><button onCLick="Choose()">Button</button></div>
<div id="random"></div>
<div id="score"></div>
<div id="lost"></div>
<script type="text/javascript">
function Choose() {
var array = [1,2,3,4];
array.shuffle();
number = array[0];
document.getElementById("random").innerHTML=("Number is: " + number);
}
</script>
<div id="cards">
<button onClick="Picker()">Card 1</button>
<button onClick="Picker()">Card 2</button>
<button onClick="Picker()">Card 3</button>
<button onClick="Picker()">Card 4</button>
<script type="text/javascript">
function Picker() {
var array2 = [1,2,3,4];
array2.shuffle();
number2 = array2[0];
if (number==0) {
alert('please pick a number first!');
}
else if (number2==number) {
alert('you won!');
var wins = document.getElementById('score');
wins.lastChild.nodeValue = wins.lastChild.nodeValue+ document.getElementById('score').value;
}
else if (number2!=number){
alert('you lost!');
var loses = document.getElementById('lost');
loses.lastChild.nodeValue = loses.lastChild.nodeValue+ document.getElementById('lost').value;
}
}
</script>
</div>
おかげでは十分ではありません –