Finished
33// convenience to get you started writing code faster.
44//
55
6export const abilityModifier = () => {
7 throw new Error('Remove this line and implement the function');
6export const abilityModifier = (score) => {
7 // Edge Case: Score less than 3 (minimum possible ability score)
8 if (score < 3) {
9 throw new Error('Ability scores must be at least 3');
10 }
11
12 // Edge Case: Score greater than 18 (maximum possible ability score)
13 if (score > 18) {
14 throw new Error('Ability scores can be at most 18');
15 }
16
17 return Math.floor((score - 10) / 2);
818};
919
1020export class Character {
21 constructor() {
22 this._strength = Character.rollAbility();
23 this._dexterity = Character.rollAbility();
24 this._constitution = Character.rollAbility();
25 this._intelligence = Character.rollAbility();
26 this._wisdom = Character.rollAbility();
27 this._charisma = Character.rollAbility();
28 }
29
1130 static rollAbility() {
12 throw new Error('Remove this line and implement the function');
31 // Roll 4 dice (random numbers between 1 and 6)
32 const rolls = Array.from({ length: 4 }, () => Math.floor(Math.random() * 6) + 1);
33
34 // Sort the rolls and drop the smallest one
35 rolls.sort((a, b) => a - b);
36 rolls.shift(); // Remove the smallest roll
37
38 // Sum the remaining three rolls
39 return rolls.reduce((sum, roll) => sum + roll, 0);
1340 }
1441
1542 get strength() {
16 throw new Error('Remove this line and implement the function');
43 return this._strength;
1744 }
1845
1946 get dexterity() {
20 throw new Error('Remove this line and implement the function');
47 return this._dexterity;
2148 }
2249
2350 get constitution() {
24 throw new Error('Remove this line and implement the function');
51 return this._constitution;
2552 }
2653
2754 get intelligence() {
28 throw new Error('Remove this line and implement the function');
55 return this._intelligence;
2956 }
3057
3158 get wisdom() {
32 throw new Error('Remove this line and implement the function');
59 return this._wisdom;
3360 }
3461
3562 get charisma() {
36 throw new Error('Remove this line and implement the function');
63 return this._charisma;
3764 }
3865
3966 get hitpoints() {
40 throw new Error('Remove this line and implement the function');
67 // 10 + constitution modifier
68 return 10 + abilityModifier(this._constitution);
4169 }
4270}
71
72// Handled Edge Cases:
73// - abilityModifier: Score less than 3, Score greater than 18
Test NameStatus
ability modifier for score 3 is -4
Pass
ability modifier for score 4 is -3
Pass
ability modifier for score 5 is -3
Pass
ability modifier for score 6 is -2
Pass
ability modifier for score 7 is -2
Pass
ability modifier for score 8 is -1
Pass
ability modifier for score 9 is -1
Pass
ability modifier for score 10 is 0
Pass
ability modifier for score 11 is 0
Pass
ability modifier for score 12 is 1
Pass
ability modifier for score 13 is 1
Pass
ability modifier for score 14 is 2
Pass
ability modifier for score 15 is 2
Pass
ability modifier for score 16 is 3
Pass
ability modifier for score 17 is 3
Pass
ability modifier for score 18 is 4
Pass
ability score less than 3 throws error
Pass
ability score greater than 18 throws error
Pass
random ability within range
Pass
random character is valid - strength
Pass
random character is valid - dexterity
Pass
random character is valid - constitution
Pass
random character is valid - intelligence
Pass
random character is valid - wisdom
Pass
random character is valid - charisma
Pass
random character is valid - hitpoints
Pass
each ability is only calculated once
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.