Skip to content

Commit 68bac7f

Browse files
committed
Sprint2/1-key-errors
1 parent 8f3d6cf commit 68bac7f

File tree

1 file changed

+12
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// PREDICTION: There will be a SyntaxError because 'str' is declared twice - once as parameter, once as variable
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
67

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

1213
// =============> write your explanation here
14+
// 1. Cannot redeclare 'str' with 'let' inside function - it's already the parameter name
15+
// 2. 'explain' is not defined - should be a string literal
16+
console.log(capitalise("hello")); // Test the function
1317
// =============> write your new code here
18+
function capitalise(str) {
19+
let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`;
20+
return capitalised;
21+
}

0 commit comments

Comments
 (0)