Lesson 12 Challenge 2 First function test
by nathanesa
JavaScript
// Function to get damage from ogre's attack.
function getOgreAttack() {
var firstRoll = Math.floor(Math.random() * 6) + 1;
var damage;
if (firstRoll < 3) {
damage = 0;
} else {
damage = Math.floor(Math.random() * 6) + 1 + Math.floor(Math.random() * 6) + 1;
}
return damage;
}
// Testing code.
document.write('Testing ogre attacks...');
document.write('<br>Damage: ' + getOgreAttack());
document.write('<br>Damage: ' + getOgreAttack());
document.write('<br>Damage: ' + getOgreAttack());
document.write('<br>Damage: ' + getOgreAttack());
document.write('<br>Damage: ' + getOgreAttack());