← All Exercises
Select the Right Plural Form
basicjavascript
Background
Plural rules differ by language: Chinese has no count agreement, French treats zero as singular. Hard-coded English rules ship broken translations.
Problem
Choose the plural form for English, French and Chinese from a "singular|plural" template and substitute the count.
Input
JSON object: { locale, count, template: "singular|plural" }Output
JSON string: the chosen form with {count} substitutedSample tests
Sample 1
Input: {"locale":"en","count":1,"template":"{count} file|{count} files"}Expected: "1 file"
Sample 2
Input: {"locale":"fr","count":0,"template":"{count} fichier|{count} fichiers"}Expected: "0 fichier"
Your solution
Learning objective
Localize counts with per-language rules instead of English defaults.