Liliana797979

hello France - mid exam - fundamentals

Aug 17th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function helloFrance(input){
  2.     let items = input.shift().split('|');
  3.     let budget = Number(input.shift());
  4.     let profit  = 0;
  5.     let result = [];
  6.     let currentMoney = budget;
  7.    
  8.     for(let i = 0; i < items.length; i++){
  9.         let splitted = items[i].split('->');
  10.         let type = splitted[0];
  11.         let price = Number(splitted[1]);
  12.        
  13.         if(price > currentMoney){
  14.             break;
  15.         }
  16.  
  17.         if(type === 'Clothes'){
  18.             if(price <= 50 ){
  19.                 let finalPrice = price * 1.4;
  20.                 profit += finalPrice;
  21.                 currentMoney -= price;
  22.                 result.push(finalPrice);
  23.             }
  24.         }
  25.          if(type === 'Shoes'){
  26.             if(price <= 35){
  27.                 let finalPrice = price * 1.4
  28.                 profit += finalPrice;
  29.                 currentMoney -= price;
  30.                 result.push(finalPrice);
  31.             }
  32.         }
  33.          if(type === 'Accessories'){
  34.             if(price <= 20.5){
  35.                 let finalPrice = price * 1.4
  36.                 profit += finalPrice;
  37.                 currentMoney -= price;
  38.                 result.push(finalPrice);
  39.             }
  40.         }
  41.     }
  42.     let sum = (profit + currentMoney) - budget;
  43.  
  44.     console.log(result.map(x => x.toFixed(2)).join(' '));
  45.     console.log(`Profit: ${sum.toFixed(2)}`);
  46.  
  47.     if(sum  + budget >= 150){
  48.         console.log(`Hello, France!`);
  49.     } else{
  50.         console.log(`Time to go.`);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment