Skip to content

Commit 1056db8

Browse files
committed
answer and fix error
1 parent f396f5f commit 1056db8

File tree

1 file changed

+17
-9
lines changed
  • Sprint-2/1-key-errors

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
"hello Mhairi" === `hello ${mhairiName}`;
2-
"${mhairiName} is 28" === `Mhairi is ${mhairiAge}`;
1+
// Predict and explain first...
2+
// it should show syntax error
33

4-
// My answer is:
5-
const mhairiName = "Mhairi";
6-
const mhairiAge = 28;
4+
// call the function capitalise with a string input
5+
// interpret the error message and figure out why an error is occurring
76

8-
const sentence1= `Hello ${mhairiName},nice to meet you`;
9-
console.log(sentence1); // ➜ Output: Hello Mhairi, nice to meet you
7+
function capitalise(str) {
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
10+
}
11+
12+
// the input "sty" is the same as output "str" which is not allowed in JS
13+
// my new code:
14+
15+
function capitalise(str) {
16+
return(`${str[0].toUpperCase()}${str. slice(1)}`)
17+
}
18+
console.log(capitalise("morning"))
19+
console.log(capitalise("heavy"))
1020

1121

12-
const sentence= `${mhairiName} is ${mhairiAge} years old`;
13-
console.log(sentence); // ➜ Output: Mhairi is 28 years old

0 commit comments

Comments
 (0)