From 2f1534e0ebe09a891413f938df2fe4a07b6a547a Mon Sep 17 00:00:00 2001 From: weixin_67016521 Date: Mon, 7 Aug 2023 16:22:35 +0800 Subject: [PATCH] Auto Commit --- index.html | 1 + script.js | 14 ++++++++++++++ style.css | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/index.html b/index.html index bffce1b..9b001c4 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ +
diff --git a/script.js b/script.js index daa7d95..8a51355 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,10 @@ // 定义变量,记录双方出拳 let playerChoice = ""; let computerChoice = ""; +var wins = 0; +var losts = 0; +var draws=0; +var rate = 0; // 定义函数,用于电脑出拳 function computerPlay() { @@ -44,15 +48,25 @@ function emojiOf(choice) { function determineOutcome(playerChoice, computerChoice) { if (playerChoice === computerChoice) { + draws++; + rate = (wins/(wins+losts)).toFixed(3); + document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString(); return " draw "; } else if ( (playerChoice === "scissors" && computerChoice === "paper") || (playerChoice === "rock" && computerChoice === "scissors") || (playerChoice === "paper" && computerChoice === "rock") ) { + wins++; + rate = (wins/(wins+losts)).toFixed(3); + document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString(); return "😊 wins !"; } else { + losts++; + rate = (wins/(wins+losts)).toFixed(3); + document.getElementById("score").innerHTML = "😊 wins: "+(wins).toString()+" 🤖️ wins: "+ losts.toString()+" odds: "+rate.toString(); return "🤖️ wins !"; } + } diff --git a/style.css b/style.css index 4d1fdbd..49465ca 100644 --- a/style.css +++ b/style.css @@ -8,6 +8,12 @@ body { justify-content: center; } +score{ + position: absolute; + top:10px; + left: 10px; +} + button { font-size: 3rem; margin: 10px; -- GitLab