Skip to content

Commit a6c7eb1

Browse files
committed
restore Sprint-3 to upstream
1 parent 9cbdc83 commit a6c7eb1

4 files changed

Lines changed: 21 additions & 67 deletions

File tree

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
// Predict and explain first...
2-
// ======> write your prediction here: I predict that the code should cut out, and make the first letter of the string an uppercase letter,
3-
// then add every letters that comes after
2+
// =============> write your prediction here
43

54
// call the function capitalise with a string input
65
// interpret the error message and figure out why an error is occurring
76

8-
// function capitalise(str) {
9-
// let str= `${str[0].toUpperCase()}${str.slice(1)}`
10-
// return str;
11-
// }
12-
13-
14-
// =============> write your explanation here: The error read "SyntaxError: Identifier 'str' has already been declared",
15-
// this is as a result of having two variables with same name. The error occoured in this code because the variable "str" has been decleared twice
16-
17-
// =============> write your new code here
18-
197
function capitalise(str) {
20-
let str2= `${str[0].toUpperCase()}${str.slice(1)}`
21-
return str2;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
2210
}
23-
console.log(capitalise("money"))
11+
12+
// =============> write your explanation here
13+
// =============> write your new code here

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
// Predict and explain first...
22

33
// Why will an error occur when this program runs?
4-
// Answer below:
5-
// An error will occur for two reasons, first because there variable "decimalNumber" being decleared
6-
// The second reason is because the function "convertToPercentage" placeholder has no value when it was called
7-
8-
// =============> write your prediction here:
9-
// Answer below:
10-
// I predicted that the code will not work because of the variable (decimalNumber) inside the function,
11-
// Also because the console.log function is not not calling the function "convertToPercentage" with a value
12-
4+
// =============> write your prediction here
135

146
// Try playing computer with the example to work out what is going on
157

16-
// function convertToPercentage(decimalNumber) {
17-
// const decimalNumber = 0.5;
18-
// const percentage = `${decimalNumber * 100}%`;
8+
function convertToPercentage(decimalNumber) {
9+
const decimalNumber = 0.5;
10+
const percentage = `${decimalNumber * 100}%`;
11+
12+
return percentage;
13+
}
1914

20-
// return percentage;
21-
// }
22-
// console.log(decimalNumber);
15+
console.log(decimalNumber);
2316

2417
// =============> write your explanation here
2518

2619
// Finally, correct the code to fix the problem
2720
// =============> write your new code here
28-
29-
function convertToPercentage(decimalNumber) {
30-
const percentage = `${decimalNumber * 100}%`;
31-
32-
return percentage;
33-
}
34-
console.log(convertToPercentage(10.5));

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11

22
// Predict and explain first BEFORE you run any code...
3-
// Answer below:
4-
// The code will not work because the placeholder variable (3) should be an actual name like "num"
5-
63

74
// this function should square any number but instead we're going to get an error
85

96
// =============> write your prediction of the error here
107

11-
// function square(3) {
12-
// return num * num;
13-
// }
8+
function square(3) {
9+
return num * num;
10+
}
1411

1512
// =============> write the error message here
16-
// SyntaxError: Unexpected number
1713

1814
// =============> explain this error message here
19-
// The error message explains the error in the function parameter (3), the function expects a name parameter instead of a number.
2015

2116
// Finally, correct the code to fix the problem
2217

2318
// =============> write your new code here
2419

25-
function square(num) {
26-
return num * num;
27-
}
28-
console.log(square(10))
29-
30-
3120

‎Sprint-3/2-mandatory-debug/0.js‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
// Predict and explain first...
2-
// Answer below:
3-
// The code needs a value inside the console.log function to multiply, but no value was useed to replace the placeholder parameters
4-
// It should be an error, no value to return
52

63
// =============> write your prediction here
74

8-
// function multiply(a, b) {
9-
// console.log(a * b);
10-
// }
11-
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
5+
function multiply(a, b) {
6+
console.log(a * b);
7+
}
128

9+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1310

1411
// =============> write your explanation here
15-
// Answer below:
16-
// The code has two function parameters, it prints the parameters without an actual value. To correct this code the console.log has to be replaced with retun
17-
// To return the value of the parameters when called
1812

1913
// Finally, correct the code to fix the problem
2014
// =============> write your new code here
21-
22-
function multiply(a, b) {
23-
return a * b
24-
}
25-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 10)}`);

0 commit comments

Comments
 (0)