@@ -16,7 +16,7 @@ function calculateSalesTax(priceOfProduct) {
1616 ===================
1717 The business has informed you that prices must have 2 decimal places
1818 They must also start with the currency symbol
19- Write a function that transforms numbers into the format £0.00
19+ Write a function that adds tax to a number, and then transforms the total into the format £0.00
2020
2121 Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
2222*/
@@ -26,37 +26,31 @@ var price=calculateSalesTax(a);
2626
2727return `£${ price . toFixed ( 2 ) } ` ;
2828}
29+ === = ===
30+ function addTaxAndFormatCurrency ( ) { }
2931
30- /* ======= TESTS - DO NOT MODIFY =====
32+ /* ======= TESTS - DO NOT MODIFY =====
3133There are some Tests in this file that will help you work out if your code is working.
32-
3334To run these tests type `node 4-tax.js` into your terminal
3435*/
3536
36- function test ( test_name , expr ) {
37- let status ;
38- if ( expr ) {
39- status = "PASSED" ;
40- } else {
41- status = "FAILED" ;
42- }
37+ const util = require ( 'util' ) ;
38+
39+ function test ( test_name , actual , expected ) {
40+ let status ;
41+ if ( actual === expected ) {
42+ status = "PASSED" ;
43+ } else {
44+ status = `FAILED: expected: ${ util . inspect ( expected ) } but your function returned: ${ util . inspect ( actual ) } ` ;
45+ }
4346
44- console . log ( `${ test_name } : ${ status } ` ) ;
47+ console . log ( `${ test_name } : ${ status } ` ) ;
4548}
4649
47- test ( "calculateSalesTax function - case 1 works" , calculateSalesTax ( 15 ) === 18 ) ;
48- test (
49- "calculateSalesTax function - case 2 works" ,
50- calculateSalesTax ( 17.5 ) === 21
51- ) ;
52- test (
53- "calculateSalesTax function - case 3 works" ,
54- calculateSalesTax ( 34 ) === 40.8
55- ) ;
56-
57- test ( "formatCurrency function - case 1 works" , formatCurrency ( 15 ) === "£18.00" ) ;
58- test (
59- "formatCurrency function - case 2 works" ,
60- formatCurrency ( 17.5 ) === "£21.00"
61- ) ;
62- test ( "formatCurrency function - case 3 works" , formatCurrency ( 34 ) === "£40.80" ) ;
50+ test ( "calculateSalesTax function - case 1 works" , calculateSalesTax ( 15 ) , 18 )
51+ test ( "calculateSalesTax function - case 2 works" , calculateSalesTax ( 17.5 ) , 21 )
52+ test ( "calculateSalesTax function - case 3 works" , calculateSalesTax ( 34 ) , 40.8 )
53+
54+ test ( "addTaxAndFormatCurrency function - case 1 works" , addTaxAndFormatCurrency ( 15 ) , "£18.00" )
55+ test ( "addTaxAndFormatCurrency function - case 2 works" , addTaxAndFormatCurrency ( 17.5 ) , "£21.00" )
56+ test ( "addTaxAndFormatCurrency function - case 3 works" , addTaxAndFormatCurrency ( 34 ) , "£40.80" )
0 commit comments