<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { background-color: black; color: yellow; } button { color: yellow; background-color: black; outline: auto; } </style> </head> <body> <p id="USER"></p> <p id="COMPUTER"></p> <p id="winner"></p> <form action=""> <button type="submit">ÚJRA</button> </form> <script> const weapons = ["kő", "papír", "olló"]; function user_input(input) { return !weapons.includes(input); } 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> </body> </html>