Advertisement
Guest User

Hello France 02

a guest
Feb 28th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function solve (input = []){
  2. let items = input.shift().split('|');
  3. let budget = Number(input.shift());
  4. let money = budget;
  5. let boughtItems = [];
  6. let increased = []
  7. let newBudget = 0;
  8. let profit = 0;
  9. for (const line of items) {
  10. let [type, price] = line.split('->');
  11. let currentPrice = Number(price);
  12. switch (type){
  13. case 'Clothes':
  14. if (currentPrice <= 50.00 && currentPrice <= money) {
  15. boughtItems.push(currentPrice);
  16. money -= currentPrice;
  17. }
  18. break;
  19. case 'Shoes':
  20. if (currentPrice <= 35.00 && currentPrice <= money) {
  21. boughtItems.push(currentPrice);
  22. money -= currentPrice;
  23. }
  24. break;
  25. case 'Accessories':
  26. if (currentPrice <= 20.50 && currentPrice <= money) {
  27. boughtItems.push(currentPrice);
  28. money -= currentPrice;
  29. }
  30. break;
  31. }
  32. }
  33. //increased = boughtItems.map(x => Number((x * 1.4).toFixed(2)))
  34. let sumOfBoughtItems = 0;
  35. for (let price of boughtItems){
  36. let increasedPrice = price * 1.4;
  37. increased.push(increasedPrice.toFixed(2));
  38. profit += price * 0.4;
  39. sumOfBoughtItems += increasedPrice;
  40. }
  41. sumOfBoughtItems += money
  42. console.log(increased.join(' '));
  43.  
  44. console.log(`Profit: ${profit.toFixed(2)}`);
  45. if (sumOfBoughtItems >= 150) {
  46. console.log('Hello, France!');
  47. } else {
  48. console.log('Time to go.');
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement