-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice-2.js
45 lines (38 loc) · 961 Bytes
/
practice-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let myCharOne = {
name: 'Zolda',
class: 'Wizard',
maxHp: 90,
currentHp: 75,
armorClass: 16,
atkBonus: 7,
magicBonus: 10
}
let myCharTwo = {
name: 'Rollo',
class: 'Sorcerer',
maxHp: 100,
currentHp: 85,
armorClass: 15,
atkBonus: 6,
magicBonus: 11
}
// Version 2
function diceRoll(min, max) {
let mathLogic = Math.floor(Math.random() * (max - min + 1)) + min;
return mathLogic
}
function atkRoll(diceResult) {
return diceResult += myCharOne.atkBonus;
}
function makeAtk(minimum, maximum) {
let theRoll = diceRoll(minimum, maximum);
let addingBonus = atkRoll(theRoll);
let printedStatement = `You rolled a ${theRoll} for a total of ${addingBonus}!`;
if (theRoll == 20) {
return `Critical Hit!! ` + printedStatement;
} else if (theRoll == 1){
return `Critical Miss!! ` + printedStatement;
} else
return printedStatement;
}
console.log(makeAtk(1, 20))