Advertisement
RRusev77

Dishwasher While Loop More exercises

Apr 14th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(...input) {
  2.     let drugCounter = Number(input.shift());
  3.     let drugVolume = drugCounter * 750;
  4.     let counter = 1;
  5.     let dishCount = input.shift();
  6.     let dishes = 0;
  7.     let pots = 0;
  8.  
  9.     while(dishCount != 'End') {
  10.         if (typeof dishCount != Number) {
  11.             dishCount = Number(dishCount);
  12.         }
  13.  
  14.         if (drugVolume < 0) {
  15.             console.log(`Not enough detergent, ${Math.abs(drugVolume)} ml. more necessary!`);
  16.             break;
  17.         }
  18.  
  19.         if (counter % 3 == 0) {
  20.             drugVolume = drugVolume - (dishCount * 15);
  21.             pots += dishCount;
  22.         } else {
  23.             drugVolume = drugVolume - (dishCount * 5);
  24.             dishes += dishCount;
  25.         }
  26.         dishCount = input.shift();
  27.         counter++;
  28.     }
  29.  
  30.     if(drugVolume >= 0) {
  31.         console.log(`Detergent was enough!`);
  32.         console.log(`${dishes} dishes and ${pots} pots were washed.`);
  33.         console.log(`Leftover detergent ${drugVolume} ml.`);
  34.     }
  35. }
  36.  
  37. solve(2, 53, 65, 55, 'End');
  38. solve(1, 10, 15, 10, 12, 13, 30);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement