S
S
Stacy None2018-02-19 17:07:31
JavaScript
Stacy None, 2018-02-19 17:07:31

How to combine two js scripts correctly?

Script that counts the number in the list and displays the number<li><ul id="list">

var numberOfLis = document.getElementById('list').children.length; 
document.getElementById('result').textContent = numberOfLis;

And there is a pluralization script that selects the correct ending of the word depending on the number
function pluralizeRus(n, forms) {
  return n % 10 == 1 && n % 100 != 11
        ? forms[0]
        : (n % 10 >= 2 && n % 10 <= 4
        && (n % 100 < 10
            || n % 100 >= 20) ? forms[1] : forms[2]);
}
alert('6 Скриншот' + pluralizeRus(6, ['', 'а', 'ов']));

Please help to display all this in one div tag.
To get the counted number by the first script and form a word depending on this number.
For example: 1 - Screenshot / 2 - Screenshot / 6 - Screenshots and so on.
Many thanks in advance to everyone!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Wolf, 2018-02-19
@Stacy11

function pluralizeRus(n, forms) {
  return n % 10 == 1 && n % 100 != 11
        ? forms[0]
        : (n % 10 >= 2 && n % 10 <= 4
        && (n % 100 < 10
            || n % 100 >= 20) ? forms[1] : forms[2]);
}

var numberOfLis = document.getElementById('list').children.length; 
document.getElementById('result').textContent = numberOfLis + ' Скриншот' + pluralizeRus(numberOfLis, ['', 'а', 'ов']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question