2017-04-16 7 views
-3

Ok das ist der Code:Wie generiere ich eine ganze Zahl zwischen 0-2? so

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

Nun, ich brauche (Korrigiert mich wenn ich falsch liege bitte) zu erzeugen, eine Zahl zwischen 0-2. Meine Idee ist (Gut, war) das:

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]); 

Irgendwelche Gedanken?

+0

'Math.floor (Math.random() * (max - min + 1) + min)' 'so Math.floor (Math.random() * 3) '! –

Antwort

0

es die folgende Art und Weise Sie Math.floor(Math.random()*3) ie Math.floor(Math.random()*(max - min + 1))

console.log(Math.floor(Math.random()*3));

Verwandte Themen