Practical work: using of conditions with functions in javascript

Task: Write method to transform number value to correct string: "копійка", "копійки", "копійок".

Implementation in Javascript:

Code

function transform (value) {
    let fin = value % 10;
    if(value > 9 && value < 21) {
        console.log("У вас " + value + " копійок ");
    }else if (fin > 1 && fin < 5) {
        console.log("У вас " + value + " копійки");
    }else if (fin > 0 && fin < 2) {
        console.log("У вас " + value + " копійка ");
    } else {
        console.log("У вас " + value + " копійок ");
    }
}

for (let cop = 0; cop < 100; cop++) {
  transform(cop);
}

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 :