Open VerdesuCodes opened 11 months ago
I made a simple code for this problem to easy to use that in the future
1 - Create the function roll dice:
function roll(d) {
return parseInt(Math.random() * d + 1)
}
2- Define the variables:
let mod = 4
let life = 100
let ac = 12
3- Attack:
function attack() {
let dice = roll(20)
if (dice + mod > ac) {
//Successful Attack
let damage = roll(8) + mod
life -= damage
} else {
//Failed Attack
}
}