Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function helloFrance(array) {
  2. let itemsList = array[0].split('|')
  3. let budget = Number(array[1])
  4. let boughtItemsPrices = []
  5. let salePrice = 0
  6. let salePriceSum = 0
  7. let profit = 0
  8.  
  9. for (let i = 0; i < itemsList.length; i++) {
  10. let [item, price] = itemsList[i].split('->')
  11. price = Number(price)
  12. let isTrue = false
  13.  
  14. if (price <= budget) {
  15. if (item === 'Clothes' && price <= 50) {
  16. isTrue = true;
  17. } else if (item === 'Shoes' && price <= 35) {
  18. isTrue = true;
  19. } else if (item === 'Accessories' && price <= 20.50) {
  20. isTrue = true;
  21. }
  22. }
  23. if (isTrue) {
  24. budget -= price
  25. salePrice = price * 1.40
  26. salePriceSum += salePrice
  27. profit += price * 0.40
  28. boughtItemsPrices.push(salePrice.toFixed(2))
  29. }
  30. }
  31.  
  32. console.log(boughtItemsPrices.join(' '))
  33. console.log(`Profit: ${profit.toFixed(2)}`)
  34. if (budget + salePriceSum >= 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