I am learning JavaScript and I want to make a simple rock paper scissors game. I want to make the computer choose the number 1, 2, or 3 at random and make the answer a variable called computerResponse. How do I do this?
var computerResponse = ???;
If this question is unclear please tell me and I will try to make it better.
Thanks in advance.
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
var computerResponse = getRandomInt(1, 3);
Taken from MDN's documentation on Math.random()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With