From bdee9eefa2e809c5229dd697a7b43f9969fa6cc1 Mon Sep 17 00:00:00 2001 From: nohetekelmariyam Date: Sat, 2 Dec 2023 15:25:31 +0000 Subject: [PATCH] ADD all --- week-2/implement/bmi.js | 12 ++++++++++++ week-2/implement/cases.js | 8 ++++++++ week-2/implement/to-pounds.js | 17 +++++++++++++++++ week-2/implement/vat.js | 10 ++++++++++ week-2/interpret/time-format.js | 20 +++++++++----------- 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/week-2/implement/bmi.js b/week-2/implement/bmi.js index 172c7c9a..19b46dfb 100644 --- a/week-2/implement/bmi.js +++ b/week-2/implement/bmi.js @@ -13,3 +13,15 @@ // Given someone's weight in kg and height in metres // When we call this function with the weight and height // Then it returns their Body Mass Index to 1 decimal place +function bmiCalculation(weight, height) { + if (typeof weight === "number" && typeof height === "number") { + const bmi = weight / (height * height); + + return `${bmi.toFixed(1)}`; + } else { + return " please use the right unit"; + } +} +var weight = 60; +var height = 1.64; +console.log(bmiCalculation(weight, height)); diff --git a/week-2/implement/cases.js b/week-2/implement/cases.js index f66bf7e3..571419f6 100644 --- a/week-2/implement/cases.js +++ b/week-2/implement/cases.js @@ -15,3 +15,11 @@ // Come up with a clear, simple name for the function // Use the string documentation to help you plan your solution +let string = ""; +function upperSnakeCase(string) { + const wordSplit = string.split(" "); + const wordToCapital = wordSplit.map((word) => word.toUpperCase()); + const wordJoin = wordToCapital.join("_"); + return wordJoin; +} +console.log(upperSnakeCase("nohe tekel mariyam")); diff --git a/week-2/implement/to-pounds.js b/week-2/implement/to-pounds.js index 7add3d05..8182864b 100644 --- a/week-2/implement/to-pounds.js +++ b/week-2/implement/to-pounds.js @@ -3,3 +3,20 @@ // Take this code and turn it into a reusable block of code. // Declare a function called toPounds with an appropriately named parameter. // Call this function a number of times to check it works for different inputs +function toPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + return `£${pounds}.${pence}`; +} +var penceString = "299p"; +console.log(toPounds(penceString)); diff --git a/week-2/implement/vat.js b/week-2/implement/vat.js index 44c38d74..fd6b1742 100644 --- a/week-2/implement/vat.js +++ b/week-2/implement/vat.js @@ -8,3 +8,13 @@ // Given a number, // When I call this function with a number // Then it returns the new price with VAT added on +function productCostWithVat(price) { + if (typeof price === "number") { + const vatPrice = price * 1.2; + return `£${vatPrice.toFixed(2)}`; + } else { + return "don't waste my time"; + } +} +var price = 399; +console.log(productCostWithVat(price)); diff --git a/week-2/interpret/time-format.js b/week-2/interpret/time-format.js index 15793e20..4e8d2616 100644 --- a/week-2/interpret/time-format.js +++ b/week-2/interpret/time-format.js @@ -19,25 +19,23 @@ function formatTimeDisplay(seconds) { console.log(formatTimeDisplay(143)); -// You can play computer with this example -// Use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// Questions - // a) When formatTimeDisplay is called how many times will pad be called? - +//3 time // Call formatTimeDisplay with an input of 143, now answer the following: // b) What value is assigned to the parameter num when pad is called for the first time? - + //remainingHours or 00 // c) What is the return value of pad when it is called for the first time? - + //00 // d) What is the value assigned to the parameter num when pad // is called for the last time in this program? Explain your answer - + //if second is less than 10 it would add 0 but now it is more than 10 so it return 23. // e) What is the return value when pad is called // for the last time in this program? Explain your answer - + // pad return 23 b/c 23 is greater than 10 // f) Research an alternative way of padding the numbers in this code. // Look up the string functions on mdn +/ //funtion pad(num) +//{ + // return num.toString().padstart(2,"0"); +//} \ No newline at end of file