Home > Blockchain >  React Inline Condition
React Inline Condition

Time:12-08

I have issues setting an inline condition for my shipping price :

cart.shippingPrice =
  country === ("France" || "United States") ? toPrice(20) : toPrice(10);

Only when I select France the condition returns 20, but I want United States to return it as well, is there a typo ?

CodePudding user response:

You need to explicitly check against each country:

country === "France" || country === "United States"

If you "fear" that more countries will come to the list, you could create an array:

const countries = ["France", "United States"]

and then do

countries.includes(country)

CodePudding user response:

In your expression and in question contents if it's returning 20 it means the condition is true.

Try:

cart.shippingPrice = (country === "France" || country === "United States) ? toPrice(20) : toPrice(10)
  • Related