From a5de4ca91a621eae2604d349d1852967a25aefee Mon Sep 17 00:00:00 2001 From: iainp5 Date: Wed, 8 Jan 2025 08:59:50 +0000 Subject: Pluralise function for hand lengths --- play.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 9fa6e69..33220a5 100644 --- a/play.js +++ b/play.js @@ -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) { -- cgit v1.2.3