summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2025-01-08 08:59:50 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2025-01-08 08:59:50 +0000
commita5de4ca91a621eae2604d349d1852967a25aefee (patch)
tree0688f64bf95e8b1b457a11460cfdf68a59add96e /play.js
parent880a66ee7e4c3d72daef37c4a1dc8cc67931bc1c (diff)
download1989-dawn-of-freedom-a5de4ca91a621eae2604d349d1852967a25aefee.tar.gz
Pluralise function for hand lengths
Diffstat (limited to 'play.js')
-rw-r--r--play.js18
1 files changed, 13 insertions, 5 deletions
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) {