mardi 5 décembre 2017

how do i make a button generate a random number and each time the button is clicked a new number is generated and added to the previous number

I need help making a button generate a random number in java script, i would like when the button is pressed for it to generate a random number between 1-10 and and then once the button is pressed again for it to generate a new random number but the sum of both number to show each time the button is presses. For example button is presses and the computer generates 3 button is presses and computer generates 2 but shows the sum of 2+3 so 5

<!DOCTYPE html>

<html>

<link rel="stylesheet" type="text/css" href="style.css">
<link href='http://ift.tt/1ZDpKn9' 
rel='stylesheet' type='text/css'>


<title>
Blackjack    
</title>    

<body>


<head>
<h1><i>BLACKJACK</i></h1> 
<h4>
Computers Cards: <input type ="text" id="computerscards">   
<br>Player 1 cards: <input type="text" id="playerscards">  
</h4>    
</head>   

<input type="button" value="start" 
onclick="document.getElementById('playerscards').value = 
random();document.getElementById('computerscards').value = 18">


<input type="button" value="deal" 
onclick="document.getElementById('playerscards).value = dealcard">

<input type="button" value="stand" onclick="">

<input type="button" value="next" onclick="">


<p>Press hit if you would like to draw another card<br> press stand if you 
do not wish to draw another card<br> press next if you want to start the 
next round</p>


</body>  

<script src="java.js"></script>  
</html>


JAVASCRIPT


var total = 
var randomnumber= Math.floor(Math.random() * 10 + 1);


function random()
{
return randomnumber;

}



function dealcard()
{

}





var total = 
var randomnumber= Math.floor(Math.random() * 10 + 1);


function random()
{
return randomnumber;

}



function dealcard()

{

}




Aucun commentaire:

Enregistrer un commentaire