Skip to content

Commit 3d7ea10

Browse files
Completed Sprint-2 1-key-errors
1 parent b31a586 commit 3d7ea10

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

Sprint-2/1-key-errors/0.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ function capitalise(str) {
99
return str;
1010
}
1111

12-
// =============> write your explanation here
13-
// =============> write your new code here
12+
// The error is on line 8.
13+
// The parameter 'str' has already been declared in the function.
14+
// Declaring 'let str' again causes the error.
15+
function capitalise(str) {
16+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
return capitalisedStr;
18+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ function convertToPercentage(decimalNumber) {
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// The parameter decimalNumber is already declared.
18+
// Declaring const decimalNumber again causes the error.
1819

1920
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
21+
function convertToPercentage(decimalNumber) {
22+
const percentage = `${decimalNumber * 100}%`;
23+
return percentage;
24+
}
25+
26+
console.log(convertToPercentage(0.5));

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
// this function should square any number but instead we're going to get an error
55

6-
// =============> write your prediction of the error here
6+
// function parameter should not be a number, it should be a variable name that holds a number.
7+
// the parameter is a placeholder for the number.
78

89
function square(3) {
910
return num * num;
1011
}
1112

12-
// =============> write the error message here
13+
// SyntaxError: Unexpected number
1314

14-
// =============> explain this error message here
15+
// The error occurs because a function parameter must be a variable name, not a number.
1516

1617
// Finally, correct the code to fix the problem
1718

18-
// =============> write your new code here
19+
function square(num) {
20+
return num * num;
21+
}
1922

2023

0 commit comments

Comments
 (0)