VerdesuCodes / jsStudies

This repository is to register my learning and evolution on JavaScript
0 stars 0 forks source link

Roll a dice and make an Attack #2

Open VerdesuCodes opened 11 months ago

VerdesuCodes commented 11 months ago
VerdesuCodes commented 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
    }
}