0

Construct message to promote deals and customer points.

var availableDeals = 20;
var activatedDeals = 5;
var maximumGems = 100;
var earnedGems = 70;

Need to build two strings:

1. 5 of 20 deals activated, 70 of 100 gems earned, spend more to earn more gems.
2. 15 deals to activate, Just 30 more gems required to unlock a deal. // when required gems <=50 use 'Just'

when there is only one deal/gem left then

3. 1 deal to activate, only 1 more gem to unlock a deal.

I tried

const getTitle = (activatedDeals, totalDeals, currentGems, maxGems, requiredGems) => {
 return R.cond([
   [R.equals(0), R.always('No deals to activate')], 
   [R.equals(activatedDeals), R.always('All deals activated')],
   [R.lt(activatedDeals), R.always(`${totalDeals - activatedDeals} deals to activate`)],
   [R.T, R.always('- deals to activate')], // Error scenario
 ])(
   totalDeals,
 ) +`, ${currentGems} of ${maxGems} gems, ${requiredGems} more gems to unlock a deal`;
}

How to concatenate string with various conditions for gems and deals?

  • ...are you working on a freemium microtransactions mobile game app? – Dai May 05 '23 at 00:56
  • 1
    There’s patterns to build these pluralizations in existing i18n utilities. I would highly recommend looking at lingui/i18next/formatjs and just use them as tools to accomplish your goal instead of building something custom (and no doubt less flexible/powerful). Edit: there’s also this https://stackoverflow.com/a/42955018/954940 – Adam Jenkins May 05 '23 at 01:01

0 Answers0