Skip to content

Commit 1df46e8

Browse files
author
russom
committed
Answer questions, explain and refactor code.
1 parent f5b9e81 commit 1df46e8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Predict and explain first...
22
// =============> write your prediction here
33

4+
// Prediction: the method toUpperCase return the character at index 0 of str as uppercase.
5+
// slice method will return the characters of str starting at index 1 excluding the first character.
6+
// the template literal combines the converted upper case first character and the rest of the string.
7+
48
// call the function capitalise with a string input
59
// interpret the error message and figure out why an error is occurring
610

@@ -10,4 +14,12 @@ function capitalise(str) {
1014
}
1115

1216
// =============> write your explanation here
17+
18+
// Explanation: 1. str declares twice.Hence it gives syntax error.
19+
// Refactor: 2. instead of returning str return can directly send back the template literal expression.
20+
1321
// =============> write your new code here
22+
23+
function capitalise(str) {
24+
return `${str[0].toUpperCase()}${str.slice(1)}`;
25+
}

0 commit comments

Comments
 (0)