Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html lang="ro">
<head>
<title>Romanian plurals</title>
</head>
<body>
<p>Number of beers: <input type="number" min="0" oninput="plural(this.value)" style="width: 5em"></p>
<p id="output">&nbsp;</p>
<p><pre style="background-color: #ddd; display: inline-block; padding: 0.7em; border-radius: 5px">
function plural(n) {
    let forms = ["bere", "beri", "de beri"];
    let index = n == 1 ? 0 : (n == 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2;
    let output = document.querySelector("#output");
    if (n.length > 0) {
        output.innerHTML = n + " " + forms[index];
    } else {
        output.innerHTML = "&amp;nbsp;";
    }
}
</pre></p>
<script>
function plural(n) {
    let forms = ["bere", "beri", "de beri"];
    let index = n == 1 ? 0 : (n == 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2;
    let output = document.querySelector("#output");
    if (n.length > 0) {
        output.innerHTML = n + " " + forms[index];
    } else {
        output.innerHTML = "&nbsp;";
    }
}
</script>
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kneekoopro
0viewers