Spocoman

Computer Firm

Jan 4th, 2022 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function computerFirm(input) {
  2.     let models = Number(input[0]);
  3.     let sales = 0;
  4.     let rating = 0;
  5.     for (let i = 1; i <= models; i++) {
  6.         let modelRating = Number(input[i]) % 10;
  7.         let modelSales = Math.floor(Number(input[i]) / 10);
  8.         if (modelRating === 2){
  9.             sales += 0;
  10.         } else if (modelRating === 3) {
  11.             sales += modelSales / 100 * 50;
  12.         } else if (modelRating === 4) {
  13.             sales += modelSales / 100 * 70;
  14.         } else if (modelRating === 5) {
  15.             sales += modelSales / 100 * 85;
  16.         } else if (modelRating === 6) {
  17.             sales += modelSales;
  18.         }
  19.         rating += modelRating;
  20.     }
  21.     console.log(`${sales.toFixed(2)}`);
  22.     console.log(`${(rating / models).toFixed(2)}`);
  23. }
  24.  
  25.  
Add Comment
Please, Sign In to add comment