Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mobileOperator(input) {
- let year = input[0];
- let type = input[1];
- let net = input[2];
- let month = Number(input[3]);
- let sum = 0;
- switch (type) {
- case "Small":
- if (year === "one") {
- sum = 9.98;
- } else {
- sum = 8.58;
- }
- break;
- case "Middle":
- if (year === "one") {
- sum = 18.99;
- } else {
- sum = 17.09;
- }
- break;
- case "Large":
- if (year === "one") {
- sum = 25.98;
- } else {
- sum = 23.59;
- }
- break;
- case "ExtraLarge":
- if (year === "one") {
- sum = 35.99;
- } else {
- sum = 31.79;
- }
- break;
- }
- if (net === "yes") {
- if (sum <= 10) {
- sum += 5.5;
- } else if (sum > 10 && sum <= 30) {
- sum += 4.35;
- } else {
- sum += 3.85;
- }
- }
- let total = sum * month;
- if (year === "two") {
- total -= 3.75 * total / 100;
- }
- console.log(`${total.toFixed(2)} lv.`);
- return;
- }
- РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
- function mobileOperator(input) {
- let year = input[0];
- let type = input[1];
- let net = input[2];
- let month = Number(input[3]);
- let sum = 0;
- switch (type) {
- case "Small":
- sum = year === "one" ? 9.98 : 8.58;
- break;
- case "Middle":
- sum = year === "one" ? 18.99 : 17.09;
- break;
- case "Large":
- sum = year === "one" ? 25.98 : 23.59;
- break;
- case "ExtraLarge":
- sum = year === "one" ? 35.99 : 31.79;
- break;
- }
- sum += net === "yes" ? (sum <= 10 ? 5.5 : sum > 30 ? 3.85 : 4.35) : 0;
- let total = sum * month;
- total -= year === "two" ? 3.75 * total / 100 : 0;
- console.log(`${total.toFixed(2)} lv.`);
- return;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function mobileOperator(input) {
- let year = input[0];
- let type = input[1];
- let net = input[2];
- let month = Number(input[3]);
- let sum = (type === "Small" ? (year === "one" ? 9.98 : 8.58)
- : type === "Middle" ? (year === "one" ? 18.99 : 17.09)
- : type === "Large" ? (year === "one" ? 25.98 : 23.59)
- : type === "ExtraLarge" ? (year === "one" ? 35.99 : 31.79) : 0);
- sum += net === "yes" ? (sum <= 10 ? 5.5 : sum > 30 ? 3.85 : 4.35) : 0;
- let total = sum * month;
- total -= year === "two" ? 3.75 * total / 100 : 0;
- console.log(`${total.toFixed(2)} lv.`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement