Skip to content

Instantly share code, notes, and snippets.

@mattische
Created December 4, 2024 08:57
Show Gist options
  • Select an option

  • Save mattische/4240c5d078441afa1ad36dda869ee56b to your computer and use it in GitHub Desktop.

Select an option

Save mattische/4240c5d078441afa1ad36dda869ee56b to your computer and use it in GitHub Desktop.
från handledning ME1634 241204
//från handledning 241204
/*
- Skapa en funktion calculateTax som tar ett pris och en momssats som argument och returnerar momsen.
Exempel: Om priset är 100 och momsen är 25%, returnera 25.
*/
/**
*
* - Skapa en funktion calculateTotalPrice som tar ett pris och en momssats som argument och:
- Använder calculateTax för att beräkna momsen.
- Returnerar priset inklusive moms.
*/
/*
- Skapa en tredje funktion printReceipt som:
- Tar ett pris och en momssats som argument.
- Använder calculateTotalPrice för att beräkna det totala priset.
- Skriver ut priset, momsen och det totala priset i konsolen.
- Anropa printReceipt med valfritt pris och momssats.
*/
function calculateTax(price, taxRate) {
let result = price * taxRate;
return result;
}
function calculateTotalPrice(price, taxRate) {
let tax = calculateTax(price, taxRate);
let totalPrice = price + tax;
return totalPrice;
}
function printReceipt(price, taxRate) {
//moms
const tax = calculateTax(price, taxRate);
//totalt pris ink moms
const totalPrice = calculateTotalPrice(price, taxRate);
//Kvittot skrivs ut:
console.log("*****************************************************");
console.log("KVITTO");
console.log("Pris:", price, "kr");
console.log("Moms: ", taxRate);
console.log("Moms i kronor: ", tax);
console.log("Totalt pris ink moms:", totalPrice, "kr");
console.log("*****************************************************");
}
module.exports = printReceipt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment