Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function paintingEggs(input) {
- let size = input[0];
- let color = input[1];
- let volume = parseInt(input[2]);
- let sum = 0;
- switch (size) {
- case "Large":
- if (color === "Red") {
- sum += 16;
- }
- else if (color === "Green") {
- sum += 12;
- }
- else if (color === "Yellow") {
- sum += 9;
- }
- break;
- case "Medium":
- if (color === "Red") {
- sum += 13;
- }
- else if (color === "Green") {
- sum += 9;
- }
- else if (color === "Yellow") {
- sum += 7;
- }
- break;
- case "Small":
- if (color === "Red") {
- sum += 9;
- }
- else if (color === "Green") {
- sum += 8;
- }
- else if (color === "Yellow") {
- sum += 5;
- }
- break;
- }
- let total = sum * volume * 0.65;
- console.log(`${total.toFixed(2)} leva.`);
- }
- Решение с тернарен оператор:
- function paintingEggs(input) {
- let size = input[0];
- let color = input[1];
- let volume = Number(input[2]);
- let sum = 0;
- if (color === "Red") {
- sum += size === "Large" ? 16 : size === "Medium" ? 13 : 9;
- } else if (color === "Green") {
- sum += size === "Large" ? 12 : size === "Medium" ? 9 : 8;
- } else if (color === "Yellow") {
- sum += size === "Large" ? 9 : size === "Medium" ? 7 : 5;
- }
- console.log(`${(sum * volume * 0.65).toFixed(2)} leva.`);
- }
Add Comment
Please, Sign In to add comment