Skip to content

Commit 620e7c7

Browse files
committed
updated all Sprint-3 files in the key errors, mandatory debug, mandatory implement and mandatory interpret folders
1 parent f97b348 commit 620e7c7

10 files changed

Lines changed: 66 additions & 6 deletions

File tree

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// It would fail at line 2 with either syntax or reference errors =============> write your prediction here
33

44
// call the function capitalise with a string input
5-
// interpret the error message and figure out why an error is occurring
5+
// interpret the error message and figure out why an error is occurring.
66

77
function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;

‎Sprint-3/1-key-errors/1.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ console.log(decimalNumber);
1717
// decimalNumber has been declared as a function and a variable within function scope=============> write your explanation here
1818
//Removing const decimalNumber still returns Syntax error if still within the function scope so it's not restricted to the function
1919

20-
// Finally, correct the code to fix the problem
20+
// Finally, correct the code to fix the problem.
2121
// =============> write your new code here
2222

2323
function convertToPercentage(decimalNumber) {

‎Sprint-3/1-key-errors/2.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Syntax errorError Unexpected number.=============> write the error message here
1212

13-
// Means Function identifier should be a name not a number =============> explain this error message here
13+
// Means Function identifier should be a name not a number =============> explain this error message here.
1414

1515
// Finally, correct the code to fix the problem
1616

‎Sprint-3/2-mandatory-debug/0.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Predict and explain first...
1+
// Predict and explain first....
22

33
// Code will fail because a , b are not declared values or double function values=============> write your prediction here
44

‎Sprint-3/2-mandatory-debug/1.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Predict and explain first...
1+
// Predict and explain first....
22
// =============> write your prediction here
33
// I think code will run without an error although not entirely sure what the empty return; will return
44

‎Sprint-3/2-mandatory-debug/2.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1212
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1313
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1414

15-
// Now run the code and compare the output to your prediction
15+
// Now run the code and compare the output to your prediction.
1616
// =============> write the output here
1717
// My prediction was close regarding line 10 as the value of num is not returned.
1818
// Explain why the output is the way it is

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@
1717
function calculateBMI(weight, height) {
1818
// return the BMI of someone based off their weight and height
1919
}
20+
21+
function calculateBMI(weight, height) {
22+
return (weight / height).toFixed(1);
23+
}
24+
console.log(`the bmi of 70 and 2.99 is ${calculateBMI(70, 2.99)}`);
25+
console.log(`the bmi of 90 and 1.96 is ${calculateBMI(90, 1.96)}`);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
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(text) {
19+
return text.trim().replace(/\s+/g, "_").toUpperCase();
20+
}
21+
22+
const result = toUpperSnakeCase("Hello there");
23+
console.log(result);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,45 @@
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+
/* const penceString = "399p";
9+
10+
const penceStringWithoutTrailingP = penceString.substring(
11+
0,
12+
penceString.length - 1
13+
);
14+
15+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
16+
const pounds = paddedPenceNumberString.substring(
17+
0,
18+
paddedPenceNumberString.length - 2
19+
);
20+
21+
const pence = paddedPenceNumberString
22+
.substring(paddedPenceNumberString.length - 2)
23+
.padEnd(2, "0");
24+
25+
console.log(`£${pounds}.${pence}`);*/
26+
27+
// Revised code:
28+
function poundsToPence(penceString) {
29+
const penceStringWithoutTrailingP = penceString.substring(
30+
0,
31+
penceString.length - 1,
32+
);
33+
34+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
35+
const pounds = paddedPenceNumberString.substring(
36+
0,
37+
paddedPenceNumberString.length - 2,
38+
);
39+
40+
const pence = paddedPenceNumberString
41+
.substring(paddedPenceNumberString.length - 2)
42+
.padEnd(2, "0");
43+
44+
return `£${pounds}.${pence}`;
45+
}
46+
console.log(poundsToPence("499p"));
47+
console.log(poundsToPence("1009p"));
48+
console.log(poundsToPence("2999p"));

‎Sprint-3/4-mandatory-interpret/time-format.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ function formatTimeDisplay(seconds) {
2222

2323
// a) When formatTimeDisplay is called how many times will pad be called?
2424
// =============> write your answer here
25+
// Pad will be called 3 times because of the 3 arguments
2526

2627
// Call formatTimeDisplay with an input of 61, now answer the following:
2728

2829
// b) What is the value assigned to num when pad is called for the first time?
2930
// =============> write your answer here
31+
0;
3032

3133
// c) What is the return value of pad when it is called for the first time?
3234
// =============> write your answer here
35+
0;
3336

3437
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3538
// =============> write your answer here
39+
// The value is 1 because the last pad argument is remainingSeconds. So 61 as the given seconds - remaining seconds = 1
3640

3741
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3842
// =============> write your answer here
43+
// The answer is 01 because of the final output for formatTimeDisplay(61) is 00:01:01. The assigned value of 1 with the length of 1, the numString = "0" + numString becomes 1

0 commit comments

Comments
 (0)