Skip to content

Commit bd4fe1f

Browse files
committed
completed 1-key-errors
1 parent 3372770 commit bd4fe1f

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
// it will take a string and turn the first letter into a capital.
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
6-
6+
// SyntaxError: Identifier 'str' has already been declared - str cannot be used twice as a variable name.
77
function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
99
return str;
1010
}
1111

1212
// =============> write your explanation here
13+
// i've changed the variable name from str to result. This corrected the error and return result.
1314
// =============> write your new code here
15+
function capitalise(str) {
16+
let result = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
console.log("result",result);
18+
return result;
19+
}
20+
capitalise("pear")

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
5+
// They have used the same variable name twice. This will cause an error. Also line 9 is not needed because the function takes a decimal as an argument.
66
// Try playing computer with the example to work out what is going on
77

88
function convertToPercentage(decimalNumber) {
@@ -15,6 +15,14 @@ function convertToPercentage(decimalNumber) {
1515
console.log(decimalNumber);
1616

1717
// =============> write your explanation here
18+
// SyntaxError: Identifier 'decimalNumber' has already been declared.
19+
// ReferenceError: decimalNumber is not defined
1820

1921
// Finally, correct the code to fix the problem
2022
// =============> write your new code here
23+
function convertToPercentage(decimalNumber) {
24+
const percentage = `${decimalNumber * 100}%`;
25+
console.log("percentage",percentage)
26+
return percentage;
27+
}
28+
convertToPercentage(0.8)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
// this function should square any number but instead we're going to get an error
55

66
// =============> write your prediction of the error here
7-
7+
// You can't put a number value into an argument.
88
function square(3) {
99
return num * num;
1010
}
1111

1212
// =============> write the error message here
13-
13+
// SyntaxError: Unexpected number
1414
// =============> explain this error message here
15-
15+
// It is not expecting a number to be in the function argument.
1616
// Finally, correct the code to fix the problem
1717

1818
// =============> write your new code here
19+
function square(num) {
20+
return num * num;
21+
}
1922

20-
23+
console.log("square",square(5))

0 commit comments

Comments
 (0)