- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Get English count number
We are required to write a JavaScript function that takes in a number and returns an English count number for it.
For example
3 returns 3rd
The code for this will be −
const num = 3; const englishCount = num => { if (num % 10 === 1 && num % 100 !== 11){ return num + "st"; }; if (num % 10 === 2 && num % 100 !== 12) { return num + "nd"; }; if (num % 10 === 3 && num % 100 !== 13) { return num + "rd"; }; return num + "th"; }; console.log(englishCount(num)); console.log(englishCount(111)); console.log(englishCount(65)); console.log(englishCount(767));
Following is the output on console −
3rd 111th 65th 767th
- Related Articles
- Count number of factors of a number - JavaScript
- JavaScript Get row count of an HTML table?
- Count characters at same position as in English alphabets in C++
- Decimal count of a Number in JavaScript
- How to count digits of given number? JavaScript
- Count of character pairs at same distance as in English alphabets in C++
- Get closest number out of array JavaScript
- Count the number of data types in an array - JavaScript
- Get the count of the number of documents in a MongoDB Collection?
- C++ code to count number of dice rolls to get target x
- Get minimum number without a Math function JavaScript
- C++ program to count number of minimum coins needed to get sum k
- What are some helpful English phrases that can improve my English?
- How to get sequence number in loops with JavaScript?
- Get the total number of same objects in JavaScript

Advertisements