-3

Ok so this is the code:

    var i = prompt('Rock, Paper or scissors?');
var b = ['Rock', 'Paper', 'Scissors'];

Now, I need to generate (Correct me if I'm wrong please) a number between 0-2. My idea is (Well, was) this:

var i = prompt('Rock, Paper or scissors?');
var b = ['Rock', 'Paper', 'Scissors'];
document.write(Math.random(0, 2));
var c = //the code I can't figure out
document.write(b[c]);

Any thoughts?

1 Answers1

2

Do it the following way Math.floor(Math.random()*3) ie Math.floor(Math.random()*(max - min + 1))

console.log(Math.floor(Math.random()*3));
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400