Evaluate whether a purchase qualifies for a special promotion by combining logical operators &&, ||, and ! with cent thresholds.
JavaScriptBeginnerWith Nexo
operadores-logicos · booleanos · expresiones
Statement
Your mission
In online store business rules, it is common to combine alternative requirements (where meeting at least one is enough) with mandatory general conditions (such as the promotion being active and the account not being blocked). Expressing each part in intermediate boolean variables prevents operator precedence bugs between &&, ||, and !.
Implement the solve(input) function, which receives a JSON object with six properties:
totalCompra: integer between 0 and 500000 (in cents).
esMiembro: boolean.
tieneCupon: boolean.
primeraCompra: boolean.
promocionActiva: boolean.
cuentaBloqueada: boolean.
Business rules:
To access the promotion, the promotion must be active (promocionActiva is true) and the account must not be blocked (cuentaBloqueada is false).
Additionally, the purchase must meet at least one of these three alternatives (with inclusive thresholds):
Being a member and purchasing for at least 30000 cents.
Having a valid coupon and purchasing for at least 15000 cents.
Making a first purchase and reaching at least 20000 cents.
Return a JSON object with those exact six properties:
cumpleRequisitos: boolean indicating whether at least one of the three alternatives above is met (without considering general promotion or account status).
motivosCumplidos: integer between 0 and 3 representing how many of the three individual alternatives were met, calculated as the sum of Number() of the three alternative booleans.
Rules and constraints
Do not use if, else, switch, the ternary operator (? :), loops, arrays, classes, or helper functions.
All monetary thresholds (15000, 20000, and 30000) are inclusive.
motivosCumplidos counts only the met alternatives, even if promocionDisponible is false.