Added start game button

Now the game does not start automatically and there's no need to refresh
This commit is contained in:
NetMan 2024-01-03 21:56:57 +01:00
parent 99a5968fbd
commit 1a8add76d8
2 changed files with 23 additions and 2 deletions

View File

@ -4,8 +4,27 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissors</title>
<style>
button {
margin: 50px;
position: absolute;
top: calc(50% - 50px);
left: calc(50% - 50px);
padding: 20px;
border: 2px solid #000;
border-radius: 35px;
background-color: #444;
color: #fff;
font-weight: 700;
font-size: xx-large;
cursor: pointer;
transform: translate(-50%, -50%);
display: block;
}
</style>
</head>
<body>
<button onclick="game(this)">Start<br>game</button>
<script src="index.js"></script>
</body>
</html>

View File

@ -43,7 +43,8 @@ const points = (() => {
playerAddPoints, computerAddPoints, reset};
})()
function game() {
function game(clickEvent) {
clickEvent.setAttribute('onclick', ' ');
points.reset();
for (let i = 0; i < 5; i++) {
@ -60,6 +61,7 @@ function game() {
}
})
} else if (confirm(`Do you wanna quit the game?`)) {
clickEvent.setAttribute('onclick', 'game(this)');
throw new Error("Exited the game on user's request");
}
}
@ -82,4 +84,4 @@ function game() {
}
}
game();
// game();