jeudi 31 octobre 2019

if statement in react JS function

I have a function that calculates a price based off of a set base_price and user input (property square footage).

I want to change the initial base_price based off of which package is selected.

for example, say the current let base_price= 159.998 is for cleaning services.

If the customer chooses photography services, the initial let base_price = 159.998 changes to a new number: let base_price = 259.998.

???what would be the best way to go about this??? using if/else?

Current code:

checkPrice = () => { 
   let base_price = 159.998;
     if(this.state.propertySqft > 2000){
   let overage = this.state.propertySqft - 2000;
   let percentage = Math.floor(overage / 500) * 10;
   base_price += base_price * (percentage / 100);


  }
     this.setState({ totalPrice: Math.round(base_price * 100) / 100 }); 
  }

Aucun commentaire:

Enregistrer un commentaire