as a means of learning Javascript I'm writing a script for a Deal Or No Deal game. I've started by assigning 10 different values to 10 boxes. The problem I have is making the box value unique, i.e. if box 1 is assigned the value of '1', no other boxes are given that value. If anyone can help I'd be most grateful.
<html>
<title>Array Test 1</title>
<head>
<script type="text/javascript">
function setBoxAmount(){
var box = ['box 1', 'box 2', 'box 3', 'box 4', 'box 5', 'box 6', 'box 7', 'box 8', 'box 9', 'box 10'];
var amount = [1,2,3,4,5,6,7,8,9,10];
var i=0;
for (i=0;i<=9;i++){
var j=Math.floor(Math.random()*10)
document.write (box[i] + ' = ' + amount[j] + '<br />');
}
}
</script>
</head>
<body>
<script type="text/javascript">
setBoxAmount()
</script>
</body>
</html>

New Topic/Question
Reply


MultiQuote




|