Advertisement
Guest User

hellofrance-js

a guest
Jun 26th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function helloFrance(input){
  2. let items = input[0].split("|");
  3. let collectedItems = [];
  4. let budget = Number(input[1]);
  5. let maxPrice = 0;
  6. let newSum = 0;
  7.  
  8. for(let i = 0; i< items.length; i++){
  9. let product = items[i].split("->")[0];
  10. let price = Number(items[i].split("->")[1]);
  11. if(product === "Clothes"){
  12. maxPrice = 50;
  13. } else if(product === "Shoes"){
  14. maxPrice = 35;
  15. } else if(product === "Accessories"){
  16. maxPrice = 20.50;
  17. }
  18. if (budget >= price && price <= maxPrice){
  19. budget -= price;
  20. collectedItems.push(price*1.4);
  21. }
  22. }
  23. for(let j = 0; j < collectedItems.length; j++){
  24. collectedItems[j] = Number(collectedItems[j].toFixed(2));
  25. newSum +=collectedItems[j];
  26. }
  27.  
  28. let profit = newSum-newSum/1.4;
  29. let currentMoney = budget+newSum;
  30.  
  31. console.log(collectedItems.join(' '));
  32. console.log(`Profit: ${profit.toFixed(2)}`);
  33.  
  34. if (currentMoney >= 150){
  35. console.log('Hello, France!');
  36. } else {
  37. console.log('Time to go.');
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement