From fa925cb12b2c86618dc870efafae61e7ccd499ff Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Fri, 10 Mar 2023 12:41:39 +0000 Subject: [PATCH 1/2] qestion 1 and 2 --- mandatory/1-syntax-errors.js | 13 ++++++++----- mandatory/2-logic-error.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..af3f9db6a 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,21 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a, b, c) { return a + b + c; } -function introduceMe(name, age) - return `Hello, my {name}` is "and I am $age years old`; +function introduceMe(name, age){ + return "Hello, my name is " + name + " and I am " + age + " years old" +} + function getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total"; + return "The total is " + total; } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9eb8c8cd7..f547435fe 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,7 +1,7 @@ // The syntax for these functions is valid but there are some errors, find them and fix them function trimWord(word) { - return wordtrim(); + return word.trim(); } function getStringLength(word) { From 30f35efcb0cf5a05516d1839b3afaacbc08b9ad3 Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:34:21 +0100 Subject: [PATCH 2/2] update 3- stoks.js --- mandatory/2-logic-error.js | 5 ++--- mandatory/3-function-output.js | 6 ++++-- mandatory/4-tax.js | 20 +++++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index f547435fe..ff5b064e1 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -5,12 +5,11 @@ function trimWord(word) { } function getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..9aa04395c 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -9,10 +9,12 @@ function combine2Words(word1, word2) { } function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together. - // Look at the test case below to understand what this function is expected to return. + return firstWord + ' ' + secondWord + ' ' + thirdWord; } + + + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..261045e04 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -1,12 +1,18 @@ /* SALES TAX ========= - A business requires a program that calculates how much the price of a product is including sales tax - Sales tax is 20% of the price of the product. + A business requires a program = information + + that calculates = what the function will do = the return + + how much the price of a product is = step 1 + including sales tax = step 2 + Sales tax is 20% of the price of the product. = information for step 2 */ -function calculateSalesTax() {} - +function calculateSalesTax(price) { + return price * 1.2; +} /* CURRENCY FORMATTING =================== @@ -17,7 +23,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + let priceWithTax = calculateSalesTax(price); + return '£' + priceWithTax.toFixed(2); + +} /* ===================================================