Well done, you have completed it, but i think instead of using if else and repeated code, you should use a hash map
To do so you have to use "Map" datatype available in JS, then do the mapping for what beats what
paper => rock
scissor => paper
rock => scissor
Then you can get the mapped value by using player weapon as a key for the hash map and if that value is equal to the computer selection, then player has beat the computer else its a win for the computer
Thank you for showing me a different perspective on writing code. But hash mapping is way too advanced for me right now. But I will definitely keep this as a future reference for when I get more advanced with using JavaScript.
Happy to help, however hash-map is advance, but here the problem is not that complex, so you should try it, once you start using the correct data structure, you will fall in love with them and effectively it will help you excel programming.
Well done, you have completed it, but i think instead of using if else and repeated code, you should use a hash map
To do so you have to use "Map" datatype available in JS, then do the mapping for what beats what
Then you can get the mapped value by using player weapon as a key for the hash map and if that value is equal to the computer selection, then player has beat the computer else its a win for the computer
Edge case will be to check first if both have selected a same weapon and then check the mapping.
Thank you for showing me a different perspective on writing code. But hash mapping is way too advanced for me right now. But I will definitely keep this as a future reference for when I get more advanced with using JavaScript.
Happy to help, however hash-map is advance, but here the problem is not that complex, so you should try it, once you start using the correct data structure, you will fall in love with them and effectively it will help you excel programming.
Nice and concise - love it