Skip to content

Commit 15dadf1

Browse files
committed
Answering the task
1 parent 8f3d6cf commit 15dadf1

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
12
// Predict and explain first...
2-
// =============> write your prediction here
3+
// =============> I predict that we will not need to write let in line 8 as str is already declared
4+
// as an argument within the function captialise.
35

46
// call the function capitalise with a string input
57
// interpret the error message and figure out why an error is occurring
68

9+
// function capitalise (str) {
10+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11+
// return str;
12+
// }
13+
14+
// capitalise ('hello');
15+
//==============> A syntaxError occurred as 'str' is being cleared.
16+
17+
718
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
19+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
920
return str;
1021
}
11-
12-
// =============> write your explanation here
13-
// =============> write your new code here
22+
console.log (capitalise ('hello'));

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
1+
12
// Predict and explain first...
23

34
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
5+
// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement.
6+
// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage.
57

68
// Try playing computer with the example to work out what is going on
79

8-
function convertToPercentage(decimalNumber) {
10+
// function convertToPercentage(decimalNumber) {
11+
// const decimalNumber = 0.5;
12+
// const percentage = `${decimalNumber * 100}%`;
13+
14+
// return percentage;
15+
//}
16+
17+
// console.log(decimalNumber);
18+
19+
// =============> A syntaxError occurred saying decimalNumber is already declared.
20+
21+
// Finally, correct the code to fix the problem
22+
// =============> write your new code here
23+
24+
function convertToPercentage() {
925
const decimalNumber = 0.5;
1026
const percentage = `${decimalNumber * 100}%`;
1127

1228
return percentage;
1329
}
1430

15-
console.log(decimalNumber);
16-
17-
// =============> write your explanation here
31+
console.log(convertToPercentage());
1832

19-
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
33+
// the new code runs without error and outputs "50%"

0 commit comments

Comments
 (0)