본문 바로가기
알고리즘/Codewars

[Codewars] Grasshopper - Terminal game combat function (8 kyu) / JavaScript

by fluss 2023. 3. 22.

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

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

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.

 

코드

function combat(health, damage) {
  let result = health - damage;
  return result < 0 ? 0 : result;
}

댓글