Here is how Math.random works. It will provide value between 0 and 1, but with only 0 included (it's [0,1) if you understand it).
So lets say you pick 0.99. When it's multiplied by 5 it will provide value that is close to 5, but not 5. When you add 1 you will be close to 6, but not at 6. And then Math.floor() kicks in and rounds the number to closest downward integer.
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
Lets say we roll 0.4 at first roll. It will result in 0.8 floored, and give 0, meaning we didn't hit the dragon. Anything over 0.5 rolled on random will results in value over 1 when multiplied, and exactly at 1 when floored, meaning we hit the dragon.
Same goes for damage. We roll 0.1 and multiply it by 5, so we get 0.5. Then we add 1 so we have 1.5 and when we floor it, we get 1. We did 1 damage.
If we roll 0.95 and multiply it by 5, we get 4.75. Then we add 1 and we're at 5.75! But, we still have to floor it so we get 5 and that is the damage we do the dragon.
That's why damage range is 1 to 5, because of the floor and because of Math.random() never being able to randomly pick 1.