Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

NW6/Nohe-Tekelmariyam/J1-Modul-week-2 #183

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see you starting to think about input validation 👍

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 = "";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this line? Where is this variable used?

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"));
Copy link

@varuna-v varuna-v Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution gets you to the right answer, but there are a few inefficiencies.

  1. This code splits the input into its component words, and then loops through the words individually to convert them to upper case. Could you instead convert to upper case at a different point to eliminate the 'map' altogether?
  2. The steps here are split by space character and then join with underscore. How might you instead replaceAll the spaces with an underscore instead? What might be the benefit or downside of doing it that way?

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍

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));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right ✅

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

00 would be the returned value of the method as you've correctly identified below. What value will be assigned to the parameter when the function is called?

// 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");
//}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right 👏