Skip to content

Commit c3bbdff

Browse files
committed
Fixed the errors in the 1-key-errors folder
1 parent 124ae45 commit c3bbdff

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> I think the variable 'str' is repeated twice in string literals.
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
@@ -9,5 +9,11 @@ function capitalise(str) {
99
return str;
1010
}
1111

12-
// =============> write your explanation here
12+
// =============> The error occurs because some parts of the code are not allowed in JS.
13+
// The variable 'str' is already declared in line 7 as a parameter
1314
// =============> write your new code here
15+
16+
function capitalise(str) {
17+
return `${str[0].toUpperCase()}${str.slice(1)}`
18+
}
19+
console.log(capitalise("shop"));

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> variable 'decimalNumber' is repeated already declared as a parameter in line 8
55

66
// Try playing computer with the example to work out what is going on
77

@@ -14,7 +14,12 @@ function convertToPercentage(decimalNumber) {
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// =============> Again, the error is a syntax error.
18+
// The variable 'decimal' is already declared as a parameter
1819

1920
// Finally, correct the code to fix the problem
2021
// =============> write your new code here
22+
23+
function convertToPercentage(decimalNumber) {
24+
return `${decimalNumber * 100}%`
25+
}

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

Lines changed: 6 additions & 3 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+
// =============> The error occurs because we have not defined 'num'
77

88
function square(3) {
99
return num * num;
1010
}
1111

12-
// =============> write the error message here
12+
// =============> It is a syntaxError: Enexpected number
1313

14-
// =============> explain this error message here
14+
// =============> In line 8, the number as a parameter is not expected; instead, a variable is expected.
1515

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

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

2023

0 commit comments

Comments
 (0)