Skip to content

Commit 074adf1

Browse files
committed
Completing Sprint-2
1 parent a42a22b commit 074adf1

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616

1717
function calculateBMI(weight, height) {
1818
// return the BMI of someone based off their weight and height
19-
}
19+
const bmi = weight / (height ^2);
20+
return Math.round(bmi * 10) / 10;
21+
}
22+
console.log(calculateBMI(70, 1.73)); // should return 23.4

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
18+
function toUpperSnakeCase(str) {
19+
// return the string in UPPER_SNAKE_CASE
20+
const upperStr = str.toUpperCase();
21+
const snakeCaseStr = upperStr.replace(/ /g, '_');
22+
return snakeCaseStr;
23+
}
24+
console.log(toUpperSnakeCase("hello there")); // should return "HELLO_THERE"
25+
console.log(toUpperSnakeCase("lord of the rings")); // should return "LORD_OF_THE_RINGS"

Sprint-2/3-mandatory-implement/3-to-pounds.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,27 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7+
8+
function toPounds(penceString) {
9+
const penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1
12+
);
13+
14+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
const pounds = paddedPenceNumberString.substring(
16+
0,
17+
paddedPenceNumberString.length - 2
18+
);
19+
20+
const pence = paddedPenceNumberString
21+
.substring(paddedPenceNumberString.length - 2)
22+
.padEnd(2, "0");
23+
24+
return ${pounds}.${pence}`;
25+
}
26+
27+
console.log(toPounds("123p")); // should return "£1.23"
28+
console.log(toPounds("5p")); // should return "£0.05"
29+
console.log(toPounds("75p")); // should return "£0.75"
30+
console.log(toPounds("1000p")); // should return "£10.00"

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function formatTimeDisplay(seconds) {
1010

1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
13+
let num = 61;
14+
console.log(formatTimeDisplay(num)); // should return "00:01:01"
15+
16+
1317

1418
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1519
// to help you answer these questions
@@ -18,17 +22,18 @@ function formatTimeDisplay(seconds) {
1822

1923
// a) When formatTimeDisplay is called how many times will pad be called?
2024
// =============> write your answer here
21-
25+
// The function pad will be called three times when formatTimeDisplay is called, once for each of; hours, minutes, and seconds.These are then passed as an argument to the pad function to ensure that they are displayed with two digits in the final output string.
2226
// Call formatTimeDisplay with an input of 61, now answer the following:
2327

2428
// b) What is the value assigned to num when pad is called for the first time?
2529
// =============> write your answer here
26-
30+
// The value assigned to num when pad is called for the first time is the totalHours value, which is 0. The value of 61 seconds is only one minute and one second, any value that includes hours must be in excess of 3600 seconds.
2731
// c) What is the return value of pad is called for the first time?
2832
// =============> write your answer here
29-
33+
// The return value of pad when it is called for the first time is "00". This is because the totalHours value is 0, and when it is converted to a string and passed to the pad function, it will be padded with a leading zero to ensure that it has two digits, resulting in "00".
3034
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3135
// =============> write your answer here
32-
36+
// The value assigned to num when pad is called for the last time in this program is the remainingSeconds value, which is 1. This is because the input of 61 seconds results in 1 second remaining after accounting for the full minute.
3337
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3438
// =============> write your answer here
39+
//This value displayed with two digits in the final output string, resulting in "01".

0 commit comments

Comments
 (0)