2024-09-13 07:25:31 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Document</title>
|
2024-09-15 06:38:54 +00:00
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
background-color: black;
|
|
|
|
color: yellow;
|
|
|
|
}
|
|
|
|
</style>
|
2024-09-13 07:25:31 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="USER"></p>
|
|
|
|
<p id="COMPUTER"></p>
|
2024-09-15 06:38:54 +00:00
|
|
|
<p id="winner"></p>
|
2024-09-13 07:25:31 +00:00
|
|
|
<script>
|
2024-09-15 06:38:54 +00:00
|
|
|
const weapons = ["kő", "papír", "olló"];
|
|
|
|
function user_input(input) {
|
|
|
|
return !weapons.includes(input);
|
|
|
|
}
|
2024-09-13 07:25:31 +00:00
|
|
|
|
2024-09-15 06:38:54 +00:00
|
|
|
function RNG(){
|
|
|
|
return (Math.random() * 10).toFixed(0) % 3;
|
|
|
|
}
|
2024-09-13 07:25:31 +00:00
|
|
|
|
2024-09-15 06:38:54 +00:00
|
|
|
function computer_choose(){
|
|
|
|
return weapons[RNG()];
|
|
|
|
}
|
2024-09-13 07:25:31 +00:00
|
|
|
|
2024-09-15 06:38:54 +00:00
|
|
|
function winner_text(user_choice, computer_choice){
|
|
|
|
if(user_choice == computer_choice){
|
|
|
|
return "Döntetlen";
|
|
|
|
} else {
|
|
|
|
if (user_choice == "kő" && computer_choice == "papír" || user_choice == "papír" && computer_choice == "olló" || user_choice == "olló" && computer_choice == "kő"){
|
|
|
|
return "Vesztettél!";
|
|
|
|
} else {
|
|
|
|
return "Nyertél!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-09-13 07:25:31 +00:00
|
|
|
|
|
|
|
|
2024-09-15 06:38:54 +00:00
|
|
|
let user_choice;
|
|
|
|
let computer_choice = computer_choose();
|
|
|
|
|
|
|
|
|
|
|
|
do{
|
|
|
|
user_choice = prompt("Kő - papír - olló").toLowerCase().trim();
|
|
|
|
}while(user_input(user_choice));
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("USER").innerHTML = `Te a ${user_choice}-t választottad`;
|
|
|
|
document.getElementById("COMPUTER").innerHTML = `A gép a ${computer_choice}-t választotta`;
|
|
|
|
|
|
|
|
document.getElementById("winner").innerHTML = winner_text(user_choice, computer_choice);
|
2024-09-13 07:25:31 +00:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|