Lesson 2. why *2?



Everythings working fine. Just wanted to know why on the second line I'm supposed to * 2?

Replace this line with your code. 

var slaying = true;

var youHit = Math.floor(Math.random() * 2);

var damageThisRound = Math.floor(Math.random()* 5 + 1);

var totalDamage =0;


The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).


The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.

so if you don't do this it'll only give you 0

Run it :slight_smile:

var test=Math.random()
var youHit = Math.floor(test);


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.