diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 38b260e55..fc23d35f4 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 +City: Batticaloa, Sri Lanka +About: I am a software engineering undergraduate and expertise in web development. +Language: JavaScript +Email: mohamedzibras2015@gmail.com + 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 @@ + + +
+ +