diff --git a/Rock_paper_scissors/index.html b/Rock_paper_scissors/index.html new file mode 100644 index 0000000..27ec935 --- /dev/null +++ b/Rock_paper_scissors/index.html @@ -0,0 +1,53 @@ + + + + + Rock,Paper and Scissor + + + + + + + + + +
+ +
+
+ +
+
+

Result

+ + + + + + + + + + + + + + + +
WinLoseTie
000
+
+
+
+ + + +
+
+ + + \ No newline at end of file diff --git a/Rock_paper_scissors/main.js b/Rock_paper_scissors/main.js new file mode 100644 index 0000000..da8493a --- /dev/null +++ b/Rock_paper_scissors/main.js @@ -0,0 +1,16 @@ +const arr = ['rock', 'paper', 'scissor']; +let wins = 0; +let losses = 0; +let ties = 0; + +function gameState(value) { + var rand = arr[Math.floor(Math.random() * 3)]; + document.getElementById("print_result").innerHTML = `You choose ${value}, computer choose ${rand}.

`; + let you_win = ((value == 'rock' && rand == "scissor") || (value == "paper" && rand == "rock") || (value == "scissor" && rand == "paper")) + let computer_win = (value == 'rock' && value == "scissor" || rand == "paper" && value == "rock" || rand == "scissor" && value == "paper") + document.getElementById("print_result").innerHTML += (you_win) ? `You Win` : (value === rand) ? `it's a Tie` : `Computer Win` + incrementScore(you_win,computer_win) +} +const incrementScore = ((user,computer) => { + user ? document.getElementById("win").innerHTML = wins += 1 : computer ? document.getElementById("lose").innerHTML = losses += 1 : document.getElementById("tie").innerHTML = ties +=1; + }); \ No newline at end of file