0
еще один вопрос javascript для noob здесь. У меня есть следующий код, но я бы хотел, чтобы каждый раз, когда игрок проигрывал или выигрывал (например, вы угадали правильные 3 раза и ошибочно 4), я хотел бы добавить «потерянный» и «счет» идентификаторов. так что в выигрыше будет «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>
благодаря недостаточно –