diff options
author | iainp5 <iain.pearce.ip@gmail.com> | 2025-01-08 08:59:50 +0000 |
---|---|---|
committer | iainp5 <iain.pearce.ip@gmail.com> | 2025-01-08 08:59:50 +0000 |
commit | a5de4ca91a621eae2604d349d1852967a25aefee (patch) | |
tree | 0688f64bf95e8b1b457a11460cfdf68a59add96e | |
parent | 880a66ee7e4c3d72daef37c4a1dc8cc67931bc1c (diff) | |
download | 1989-dawn-of-freedom-a5de4ca91a621eae2604d349d1852967a25aefee.tar.gz |
Pluralise function for hand lengths
-rw-r--r-- | play.js | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -753,14 +753,14 @@ function on_update() { // UPDATE PLAYER INFO if (view.is_pwr_struggle) { - roles.Democrat.stat.textContent = `${view.democrat_power_hand} Power cards` - roles.Communist.stat.textContent = `${view.communist_power_hand} Power cards` + roles.Democrat.stat.textContent = `${pluralize(view.democrat_power_hand, 'Power card')}` + roles.Communist.stat.textContent = `${pluralize(view.communist_power_hand, 'Power card')}` } else { - roles.Democrat.stat.textContent = `${view.democrat_hand} cards` - roles.Communist.stat.innerText = `${view.communist_hand} cards` + roles.Democrat.stat.textContent = `${pluralize(view.democrat_hand,'card')}` + roles.Communist.stat.innerText = `${pluralize(view.communist_hand, 'card')}` } - ui.turn_info.innerText = `Strategy deck: ${view.strategy_deck} cards` + ui.turn_info.innerText = `Strategy deck: ${pluralize(view.strategy_deck, 'card')}` // UPDATE TRACK MARKERS @@ -1152,6 +1152,14 @@ function on_log(text, ix) { return p } +const pluralize = (count, noun, suffix = 's') => { + if (Math.abs(count) === 1) { + return `${count} ${noun}` + } else { + return `${count} ${noun}${suffix}` + } +} + // =========================== VISUAL FUNCTIONS ==========================================# function on_focus_card_tip(card_number) { |