From 42542a2373225b514fff9c0420481a512ae92d15 Mon Sep 17 00:00:00 2001 From: ZibrasIsmail Date: Fri, 22 Oct 2021 18:46:01 +0530 Subject: [PATCH 1/3] Create a Stone Paper Scissor game --- Stone-Paper-Scissor-game/app.js | 54 +++++++++++++++++++++++++++++ Stone-Paper-Scissor-game/index.html | 19 ++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Stone-Paper-Scissor-game/app.js create mode 100644 Stone-Paper-Scissor-game/index.html diff --git a/Stone-Paper-Scissor-game/app.js b/Stone-Paper-Scissor-game/app.js new file mode 100644 index 000000000..b86788207 --- /dev/null +++ b/Stone-Paper-Scissor-game/app.js @@ -0,0 +1,54 @@ +const computerChoiceDisplay = document.getElementById('computer-choice') +const userChoiceDisplay = document.getElementById('user-choice') +const resultDisplay = document.getElementById('result') +const possibleChoices = document.querySelectorAll('button') +let userChoice +let computerChoice +let result + +possibleChoices.forEach(possibleChoice => possibleChoice.addEventListener('click', (e) => { + userChoice = e.target.id + userChoiceDisplay.innerHTML = userChoice + generateComputerChoice() + getResult() +})) + +function generateComputerChoice() { + const randomNumber = Math.floor(Math.random() * 3) + 1 // or you can use possibleChoices.length + + if (randomNumber === 1) { + computerChoice = 'stone' + } + if (randomNumber === 2) { + computerChoice = 'scissors' + } + if (randomNumber === 3) { + computerChoice = 'paper' + } + computerChoiceDisplay.innerHTML = computerChoice +} + +function getResult() { + if (computerChoice === userChoice) { + result = 'its a draw!' + } + if (computerChoice === 'stone' && userChoice === "paper") { + result = 'you win!' + } + if (computerChoice === 'stone' && userChoice === "scissors") { + result = 'you lost!' + } + if (computerChoice === 'paper' && userChoice === "scissors") { + result = 'you win!' + } + if (computerChoice === 'paper' && userChoice === "stone") { + result = 'you lose!' + } + if (computerChoice === 'scissors' && userChoice === "stone") { + result = 'you win!' + } + if (computerChoice === 'scissors' && userChoice === "paper") { + result = 'you lose!' + } + resultDisplay.innerHTML = result +} \ No newline at end of file diff --git a/Stone-Paper-Scissor-game/index.html b/Stone-Paper-Scissor-game/index.html new file mode 100644 index 000000000..7c5760c2a --- /dev/null +++ b/Stone-Paper-Scissor-game/index.html @@ -0,0 +1,19 @@ + + + + + Stone Paper Scissors Tutorial + + + +

Computer Choice:

+

Your Choice:

+

Result:

+ + + + + + + + \ No newline at end of file From 27bcee98c981d35b08bddb602c4bb5a688cd122a Mon Sep 17 00:00:00 2001 From: Zibras Ismail <59764125+ZibrasIsmail@users.noreply.github.com> Date: Fri, 22 Oct 2021 18:50:42 +0530 Subject: [PATCH 2/3] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 38b260e55..8693c59f8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -15,3 +15,10 @@ https://github.com/wmt-rn-shubham Name: Vishwa Desai https://github.com/wmt-vishwad +Name: Zibras Ismail +https://github.com/ZibrasIsmail +Batticaloa, Sri Lanka +I am a software engineering undergraduate and expertise in web development. +JavaScript +mohamedzibras2015@gmail.com + From ce3c2685e80acba10ae4c1ae9322833dd84e274d Mon Sep 17 00:00:00 2001 From: Zibras Ismail <59764125+ZibrasIsmail@users.noreply.github.com> Date: Fri, 22 Oct 2021 18:51:24 +0530 Subject: [PATCH 3/3] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8693c59f8..fc23d35f4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -17,8 +17,8 @@ https://github.com/wmt-vishwad Name: Zibras Ismail https://github.com/ZibrasIsmail -Batticaloa, Sri Lanka -I am a software engineering undergraduate and expertise in web development. -JavaScript -mohamedzibras2015@gmail.com +City: Batticaloa, Sri Lanka +About: I am a software engineering undergraduate and expertise in web development. +Language: JavaScript +Email: mohamedzibras2015@gmail.com