TZinovieva

Gymnastics JS

Dec 7th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gymnastics(input) {
  2.     let country = input[0];
  3.     let apparatus = input[1];
  4.  
  5.     let difficulty = 0;
  6.     let performance = 0;
  7.  
  8.     switch (country) {
  9.         case "Russia":
  10.             if (apparatus === "ribbon") {
  11.                 difficulty = 9.100;
  12.                 performance = 9.400;
  13.             } else if (apparatus === "hoop") {
  14.                 difficulty = 9.300;
  15.                 performance = 9.800;
  16.             } else {
  17.                 difficulty = 9.600;
  18.                 performance = 9.000;
  19.             }
  20.             break;
  21.         case "Bulgaria":
  22.             if (apparatus === "ribbon") {
  23.                 difficulty = 9.600;
  24.                 performance = 9.400;
  25.             } else if (apparatus === "hoop") {
  26.                 difficulty = 9.550;
  27.                 performance = 9.750;
  28.             } else {
  29.                 difficulty = 9.500;
  30.                 performance = 9.400;
  31.             }
  32.             break;
  33.         case "Italy":
  34.             if (apparatus === "ribbon") {
  35.                 difficulty = 9.200;
  36.                 performance = 9.500;
  37.             } else if (apparatus === "hoop") {
  38.                 difficulty = 9.450;
  39.                 performance = 9.350;
  40.             } else {
  41.                 difficulty = 9.700;
  42.                 performance = 9.150;
  43.             }
  44.             break;
  45.     }
  46.     let totalRating = difficulty + performance;
  47.     let maximumPoints = 20;
  48.     let percentageNeeded = (maximumPoints - totalRating) * 100 / 20;
  49.  
  50.     console.log(`The team of ${country} get ${totalRating.toFixed(3)} on ${apparatus}.`);
  51.     console.log(`${percentageNeeded.toFixed(2)}%`);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment