finished ko-papir-ollo
This commit is contained in:
parent
4809dbce1a
commit
069a8d0cd3
|
@ -4,35 +4,58 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
color: yellow;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p id="USER"></p>
|
<p id="USER"></p>
|
||||||
<p id="COMPUTER"></p>
|
<p id="COMPUTER"></p>
|
||||||
|
<p id="winner"></p>
|
||||||
<script>
|
<script>
|
||||||
let weapon;
|
const weapons = ["kő", "papír", "olló"];
|
||||||
let weapons = ["kő", "papír", "olló"];
|
function user_input(input) {
|
||||||
let computer_choice = weapons[((Math.random() * 10) % 3).toFixed(0)];
|
return !weapons.includes(input);
|
||||||
do{
|
|
||||||
weapon = prompt("Kő - papír - olló").toLowerCase();
|
|
||||||
}while(!weapons.includes(weapon));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.getElementById("USER").innerHTML = weapon;
|
|
||||||
document.getElementById("COMPUTER").innerHTML = computer_choice;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (weapon) {
|
|
||||||
case value:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function RNG(){
|
||||||
|
return (Math.random() * 10).toFixed(0) % 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
function computer_choose(){
|
||||||
|
return weapons[RNG()];
|
||||||
|
}
|
||||||
|
|
||||||
|
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!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user