Skip to content

Commit 3365fc9

Browse files
committed
corrected issues raised from run 1
1 parent 620e7c7 commit 3365fc9

9 files changed

Lines changed: 36 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function capitalise(str) {
1010
}
1111
console.log(capitalise("beautiful"));
1212

13-
// function is assigned 2 arguments/values=============> write your explanation here
13+
// write your explanation here:
14+
// Syntax Error: Identifier 'Str' has been already been declared/assigned
15+
// The error means Str had already been identified in the function capitalise(str). Let str is assigning a second value which is causing that error message
16+
1417
// =============> write your new code here
1518

1619
function capitalise(str) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Predict and explain first...
22

33
// Why will an error occur when this program runs?
4-
// decimalNumber is called twice=============> write your prediction here
4+
// write your prediction here
5+
// This is because the variable name for the parameter and the cont is the same
56

67
// Try playing computer with the example to work out what is going on
78

@@ -14,8 +15,9 @@ function convertToPercentage(decimalNumber) {
1415

1516
console.log(decimalNumber);
1617

17-
// decimalNumber has been declared as a function and a variable within function scope=============> write your explanation here
18-
//Removing const decimalNumber still returns Syntax error if still within the function scope so it's not restricted to the function
18+
//=============> write your explanation here
19+
//The decimalNumber is declared twice as a result, calling convertToPercentage function and passing a value gets assigned to parameter decimalNumber
20+
//So i had to move it outside of the function scope to remove restrictions
1921

2022
// Finally, correct the code to fix the problem.
2123
// =============> write your new code here

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// Syntax errorError Unexpected number.=============> write the error message here
1212

1313
// Means Function identifier should be a name not a number =============> explain this error message here.
14+
// Whats the difference between function identifier and parameter?
15+
// I believe function and identifier and parameter can be used interchangeably. So Parsing number 3 into the parameter would throw an error.
16+
// Changing number 3 to 'num' as a placeholder fixes the error
1417

1518
// Finally, correct the code to fix the problem
1619

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

1111
// =============> write your explanation here
1212
//The 2nd console log returned value value is undefined. I have added a return function to output the multiply value.
13-
// Finally, correct the code to fix the problem
13+
//The value returned by the function was undefined because the value hasn't been stored anywhere, and there's no return to return the value to the function call.
14+
15+
//Finally, correct the code to fix the problem
1416
// =============> write your new code here
1517
function multiply(a, b) {
1618
console.log(a * b);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function sum(a, b) {
99

1010
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1111

12-
// Maybe that unassigned return; may cause the code not to run fully =============> write your explanation here
12+
// =============> write your explanation here
13+
// The return statement was placed before the expression hence the undefined outcome. The parsed argument is not receiving output.
14+
1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
1517
function sum(a, b) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function calculateBMI(weight, height) {
1919
}
2020

2121
function calculateBMI(weight, height) {
22-
return (weight / height).toFixed(1);
22+
// return (weight / height).toFixed(1); - 1st attempt
23+
return (weight / (height * height)).toString().slice(0, 4);
2324
}
25+
2426
console.log(`the bmi of 70 and 2.99 is ${calculateBMI(70, 2.99)}`);
2527
console.log(`the bmi of 90 and 1.96 is ${calculateBMI(90, 1.96)}`);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
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+
//
1718

1819
function toUpperSnakeCase(text) {
19-
return text.trim().replace(/\s+/g, "_").toUpperCase();
20+
// return text.trim().replace(/\s+/g, "_").toUpperCase(); - first attempt that inserted underscore
21+
return text.toUpperCase().replaceAll(" ", "_");
2022
}
2123

22-
const result = toUpperSnakeCase("Hello there");
23-
console.log(result);
24+
const text = toUpperSnakeCase("Hello there");
25+
console.log(text);
26+
27+
// Trim and regex pattern was the only saving grace I came across to resolve the underscore issue I had spent hours researching.
28+
// I have however now modified and replaced the pattern for easy understanding with AI's help

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const pence = paddedPenceNumberString
2525
console.log(`£${pounds}.${pence}`);*/
2626

2727
// Revised code:
28-
function poundsToPence(penceString) {
28+
function toPounds(penceString) {
2929
const penceStringWithoutTrailingP = penceString.substring(
3030
0,
3131
penceString.length - 1,
@@ -43,6 +43,8 @@ function poundsToPence(penceString) {
4343

4444
return `£${pounds}.${pence}`;
4545
}
46-
console.log(poundsToPence("499p"));
47-
console.log(poundsToPence("1009p"));
48-
console.log(poundsToPence("2999p"));
46+
console.log(toPounds("499p"));
47+
console.log(toPounds("1009p"));
48+
console.log(toPounds("2999p"));
49+
50+
// updated function name

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function formatTimeDisplay(seconds) {
3232

3333
// c) What is the return value of pad when it is called for the first time?
3434
// =============> write your answer here
35-
0;
35+
//00;
3636

3737
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3838
// =============> write your answer here

0 commit comments

Comments
 (0)