module.exports = { slug: "discount-and-markup", title: "Discount and markup", deck_category: "finance", description: "Applies a percentage discount or a percentage markup to a price and returns the new price and the dollar change.", inputs: [ { name: "price", type: "number", unit: "currency units", required: true, description: "Original price", min: 0 }, { name: "percent", type: "number", unit: "%", required: true, description: "Discount or markup percentage", min: 0 }, { name: "mode", type: "string", required: true, description: "Whether to apply a discount or a markup", enum: ["discount", "markup"] } ], outputs: [ { name: "new_price", unit: "currency units", description: "Price after the discount or markup" }, { name: "amount_change", unit: "currency units", description: "Dollar amount of the discount or markup" } ], steps: [ "Convert the percent to a decimal: p = percent / 100.", "amount_change = price * p.", "If mode is discount, new_price = price - amount_change; if mode is markup, new_price = price + amount_change.", "Round new_price and amount_change to 2 decimals (money to cents)." ], constants: [], sources: [ { kind: "url", value: "https://www.consumerfinance.gov/consumer-tools/educator-tools/your-money-your-goals/toolkit/", title: "Your Money, Your Goals: percentage discount and markup conventions", publisher: "Consumer Financial Protection Bureau", retrieved_utc: "2026-09-30T19:31:29Z", note: "Standard retail-math discount/markup convention applied to the original price" } ], disclaimer: null, questionText(inputs) { const verb = inputs.mode === "discount" ? "discounted by" : "marked up by"; return `A $${inputs.price} price is ${verb} ${inputs.percent}%. What is the new price?`; }, run(inputs) { const { price, percent, mode } = inputs; if (typeof price !== "number" || price < 0) throw new Error("price must be a non-negative number"); if (typeof percent !== "number" || percent < 0) throw new Error("percent must be a non-negative number"); if (mode !== "discount" && mode !== "markup") throw new Error("mode must be 'discount' or 'markup'"); const p = percent / 100; const amount_change = Math.round(price * p * 100) / 100; const new_price = Math.round((mode === "discount" ? price - amount_change : price + amount_change) * 100) / 100; const fmt = (n) => n.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ","); return { answer: `$${fmt(new_price)}`, values: { new_price, amount_change } }; }, examples: [ { name: "worked example", inputs: { price: 80, percent: 25, mode: "discount" }, expected: { answer: "$60.00" }, check: "hand computation: amount_change = 80*0.25 = 20.00; new_price = 80-20 = 60.00" }, { name: "test vector: markup", inputs: { price: 150, percent: 40, mode: "markup" }, expected: { answer: "$210.00" }, check: "hand computation: amount_change = 150*0.40 = 60.00; new_price = 150+60 = 210.00" } ] };