Prohause

Travel Plans

Jun 10th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. function travel(input) {
  2. let specialized = ['Programming', 'Hardware maintenance', 'Cooking', 'Translating', 'Designing'];
  3. let average = ['Driving', 'Managing', 'Fishing', 'Gardening'];
  4. let clumsy = ['Singing', 'Accounting', 'Teaching', 'Exam-Making', 'Acting', 'Writing', 'Lecturing', 'Modeling', 'Nursing'];
  5.  
  6. let total = 0;
  7. let specCount = 0;
  8. let clumsyCount = 0;
  9.  
  10. for (const obj of input) {
  11. let [type, amount] = obj.split(' : ');
  12. amount = Number(amount);
  13. if (specialized.includes(type)&&amount>=200) {
  14. specCount++;
  15. total+=amount*0.8;
  16. if (specCount % 2 === 0) {
  17. total+=200;
  18. }
  19. continue;
  20. }
  21. if (average.includes(type)) {
  22. total+= amount;
  23. continue;
  24. }
  25. if (clumsy.includes(type)) {
  26. clumsyCount++;
  27. if (clumsyCount % 2 === 0) {
  28. amount*=0.95;
  29. }
  30. else if (clumsyCount % 3 === 0) {
  31. amount*=0.9;
  32. }
  33. total+=amount;
  34. continue;
  35.  
  36. }
  37.  
  38. }
  39. console.log(`Final sum: ${total.toFixed(2)}`);
  40. if (total < 1000) {
  41. console.log(`Mariyka need to earn ${(1000-total).toFixed(2)} gold more to continue in the next task.`);
  42. }
  43. else {
  44. console.log(`Mariyka earned ${(total-1000).toFixed(2)} gold more.`);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment