Skip to content

Commit

Permalink
ADD all
Browse files Browse the repository at this point in the history
  • Loading branch information
nohetekelmariyam committed Dec 2, 2023
1 parent 0c7233b commit bdee9ee
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
12 changes: 12 additions & 0 deletions week-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
8 changes: 8 additions & 0 deletions week-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
17 changes: 17 additions & 0 deletions week-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
10 changes: 10 additions & 0 deletions week-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
20 changes: 9 additions & 11 deletions week-2/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
//}

0 comments on commit bdee9ee

Please sign in to comment.