Practical work: using of conditions in javascript

Task: Transform years in number format to correct string: "лет", "года", "год".

Implementation in Javascript:

Code

    for (let n = 0; n < 100; n++) {
        let fin = n % 10;
        if(n > 9 && n < 21) {
            console.log("Вам " + n + " лет");
        } else if (fin > 1 && fin < 5) {
            console.log("Вам " + n + " годa");
        } else if (fin > 0 && fin < 2) {
            console.log("Вам " + n + " год");
        } else {
            console.log("Вам " + n + " лет");
        }
    }

Result:

If you have more tasks or exercises, please write them in the comments.

Thank you, good bye!

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :