<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-wi…
madhankumar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cricket Game</title>
<style>
body{
text-align:center;
}
</style>
</head>
<body>
<h1>Bat Ball Stump Game</h1>
<button onclick="
let randomNumber=Math.random()*3;
let computerChoice;
if(randomNumber>0 && randomNumber<=1){
computerChoice='Bat';
// console.log('computer choice is Bat');
}else if(randomNumber>1 && randomNumber<=2){
computerChoice='Ball';
// console.log('computer choice is Ball');
}else{
computerChoice='Stump';
// console.log('computer choice is Stump');
}
let resultMsg;
if(computerChoice ==='Ball'){
resultMsg='User won.';
}else if(computerChoice==='Bat'){
resultMsg=`It's a tie`;
}else if(computerChoice==='Stump'){
resultMsg='Computer has won';
}
alert(`you have chosen Bat .computer choice is ${computerChoice} and ${resultMsg}`);
">Bat</button>
<button onclick="
randomNumber=Math.random()*3;
computerChoice;
if(randomNumber>0 && randomNumber<=1){
computerChoice='Bat';
// console.log('computer choice is Bat');
}else if(randomNumber>1 && randomNumber<=2){
computerChoice='Ball';
// console.log('computer choice is Ball');
}else{
computerChoice='Stump';
// console.log('computer choice is Stump');
}
resultMsg;
if(computerChoice ==='Ball'){
resultMsg=`it's a tie`;
}else if(computerChoice==='Bat'){
resultMsg=`Computer has won`;
}else if(computerChoice==='Stump'){
resultMsg='User won';
}
alert(`you have chosen Ball .computer choice is ${computerChoice} and ${resultMsg}`);
">Ball</button>
<button>Stump</button>
</body>
</html>
Kindly check ball button code sir