Skip to content

Commit 876bf7b

Browse files
author
Payman IB
committed
Fix variable shadowing in capitalise function and update console log; correct convertToPercentage function implementation
1 parent 2c6aae7 commit 876bf7b

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Predict and explain first...
22
// =============> write your prediction here
33
// it gives us an error.
4-
54
// call the function capitalise with a string input
65
// interpret the error message and figure out why an error is occurring
76

87
// function capitalise(str) {
9-
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10-
// return str;
8+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
// return str;
1110
// }
1211

13-
// =============> write your explanation here :
12+
// =============> write your explanation here :
1413
// as the variable in side the function has the same name as the function variable.
1514
// =============> write your new code here
1615
function capitalise(str) {
1716
let str1 = `${str[0].toUpperCase()}${str.slice(1)}`;
1817
return str1;
1918
}
20-
console.log(capitalise("abcd"));
19+
console.log(capitalise("abcd"));

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
// Predict and explain first...
2-
3-
// Why will an error occur when this program runs?
2+
// error on line 11
3+
// error on line 17
4+
// Why will an error occur when this program runs? yes
45
// =============> write your prediction here
6+
// decimalNumber is declared before and can not be declared again.
7+
// console.log(decimalNumber) should be console.log(convertToPercentage)
8+
// Try playing computer with the example to work ot what is going on
59

6-
// Try playing computer with the example to work out what is going on
7-
8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
10+
// function convertToPercentage(decimalNumber) {
11+
// // const decimalNumber = 0.5;
12+
// const percentage = `${decimalNumber * 100}%`;
1113

12-
return percentage;
13-
}
14+
// return percentage;
15+
// }
1416

15-
console.log(decimalNumber);
17+
//console.log(percentage);
1618

1719
// =============> write your explanation here
20+
// decimalNumber is declared before and can not be declared again.
21+
// console.log(decimalNumber) should be console.log(convertToPercentage)
1822

1923
// Finally, correct the code to fix the problem
2024
// =============> write your new code here
25+
function convertToPercentage(decimalNumber) {
26+
//const decimalNumber = 0.5;
27+
const percentage = `${decimalNumber * 100}%`;
28+
29+
return percentage;
30+
}
31+
32+
console.log(convertToPercentage(0.5));

Sprint-2/2-mandatory-debug/new.js

Whitespace-only changes.

0 commit comments

Comments
 (0)