Advertisement
Guest User

Untitled

a guest
Jun 16th, 2022
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function computerStore(arr){
  2.    let clientType = arr.pop();
  3.    let totalPriceBeforTaxes= 0;
  4.    let finalPrice = 0;
  5.    
  6.    for(let i = 0; i < arr.length ; i++){
  7.       arr[i] = Number(arr[i])
  8.    }
  9.    for(let num of arr){
  10.      if(num > 0){
  11.          totalPriceBeforTaxes+=num
  12.      }else{
  13.       console.log('Invalid price!')
  14.      }
  15.    }
  16.    
  17.    if(clientType !== "special"){
  18.       finalPrice = totalPriceBeforTaxes + (totalPriceBeforTaxes * 0.2);
  19.    }else{
  20.       let discount = 0.1;
  21.       finalPrice = (totalPriceBeforTaxes +(totalPriceBeforTaxes * 0.2)) - ((totalPriceBeforTaxes +(totalPriceBeforTaxes * 0.2))* discount)
  22.    }
  23.  
  24.    if (finalPrice > 0) {
  25.    console.log(`Congratulations you've just bought a new computer!
  26. Price without taxes: ${totalPriceBeforTaxes.toFixed(2)}$
  27. Taxes: ${(totalPriceBeforTaxes * 0.2).toFixed(2)}$`);
  28.   console.log("-----------")
  29.   console.log(`Total price: ${finalPrice.toFixed(2)}$`)
  30.   } else {
  31.     console.log('Invalid order!')
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement