Skip to content

Commit

Permalink
Grasshopper - Terminal game combat function
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed May 18, 2024
1 parent 90b1aa0 commit 9dc4787
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions 8_kyu/Grasshopper - Terminal game combat function/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Grasshopper - Terminal game combat function

https://www.codewars.com/kata/586c1cf4b98de0399300001d

Create a combat function that takes the player's current health and the amount of damage recieved, and returns the player's new health. Health can't be less than **0**.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { combat } from "./index";

describe("Tests", () => {
it("combat", () => {
expect(combat(100, 5)).toBe(95);
expect(combat(92, 8)).toBe(84);
expect(combat(20, 30)).toBe(0);
});
});
5 changes: 5 additions & 0 deletions 8_kyu/Grasshopper - Terminal game combat function/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function combat(health: number, damage: number): number {
const result = health - damage;

return result > 0 ? result : 0;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

### Katas solved

`Total`: 30 \
`8_kyu`: 29 \
`Total`: 31 \
`8_kyu`: 30 \
`7_kyu`: 0 \
`6_kyu`: 1 \
`5_kyu`: 0 \
Expand Down

0 comments on commit 9dc4787

Please sign in to comment.