dimanche 15 décembre 2019

Use if-loop to calculate price depending on the input in js

I'm pretty new to Javascript and React, so please bear with me. I have a component in my app, that is taking a timespan from the user, but now I want to calculate the price the user would have to day, depending on his input. I figured taht it would probably be the easiest way to use an if loop but something is very off with that and I am a little stuck.

Is my attempt okay in general or does it need a separate function that I have to call in order to do what I want to do?

 onConfirm(hour, minute) {
    this.setState({ time: `Dauer: ${hour}:${minute}` });
    this.setState(if((hour) < 4){return price = `Preis: (${hour}* 1.5) €';}
      else {return price= 'Preis: 5.50 €';} );
    this.TimePicker.close();
  }

Aucun commentaire:

Enregistrer un commentaire