Skip to content

Commit d2210f1

Browse files
committed
Fix: Remove accidentally committed Sprint 2 files
1 parent e4ad14a commit d2210f1

File tree

6 files changed

+20
-55
lines changed

6 files changed

+20
-55
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
// It will crash with a SyntaxError. We can't use 'let' to declare 'str' because 'str' is already taken by the function parameter.
3+
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
6-
/* I commented this out so it doesn't crash:
6+
77
function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
99
return str;
1010
}
11-
*/
11+
1212
// =============> write your explanation here
13-
//The error confirms "str has already been declared". Function parameters act as local variables, creating a naming conflict with `let str`.
1413
// =============> write your new code here
15-
function capitalise(str) {
16-
return `${str[0].toUpperCase()}${str.slice(1)}`;
17-
}
18-
console.log(capitalise("hello"));

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
// It will crash for two reasons. 1. Trying to log a local variable 'decimalNumber' outside its function. 2. Trying to re-declare the parameter 'decimalNumber' using 'const' inside the function.
5+
66
// Try playing computer with the example to work out what is going on
7-
/* Commented out broken code:
7+
88
function convertToPercentage(decimalNumber) {
99
const decimalNumber = 0.5;
1010
const percentage = `${decimalNumber * 100}%`;
@@ -13,12 +13,8 @@ function convertToPercentage(decimalNumber) {
1313
}
1414

1515
console.log(decimalNumber);
16-
*/
16+
1717
// =============> write your explanation here
18-
// 'decimalNumber' is scoped to the function, so console.log outside can't see it (ReferenceError). Inside, re-declaring the parameter with 'const' causes a SyntaxError. Also, the function was never actually called.
18+
1919
// Finally, correct the code to fix the problem
2020
// =============> write your new code here
21-
function convertToPercentage(decimalNumber) {
22-
return `${decimalNumber * 100}%`;
23-
}
24-
console.log(convertToPercentage(0.5));

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
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-
// Syntax error. We put a hardcoded number '3' where a parameter name (like 'num') should be.
8-
/* Commented out the broken code so it doesn't crash:
7+
98
function square(3) {
109
return num * num;
1110
}
12-
*/
11+
1312
// =============> write the error message here
14-
// SyntaxError: Unexpected number
13+
1514
// =============> explain this error message here
16-
// Function definitions require variable names as parameters to act as placeholders, not literal values.
15+
1716
// Finally, correct the code to fix the problem
1817

1918
// =============> write your new code here
20-
function square(num) {
21-
return num * num;
22-
}
23-
console.log(square(3));
24-
console.log(square(4));
19+
2520

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

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

33
// =============> write your prediction here
4-
//It will print "320", followed by "The result... is undefined". The function lacks a return value.
5-
/* Commented out the broken code:
4+
65
function multiply(a, b) {
76
console.log(a * b);
87
}
98

109
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
11-
*/
10+
1211
// =============> write your explanation here
13-
// `console.log` just prints to the screen. Without a `return` statement, the function evaluates to `undefined`, which gets injected into the template literal.
12+
1413
// Finally, correct the code to fix the problem
1514
// =============> write your new code here
16-
function multiply(a, b) {
17-
return a * b;
18-
}
19-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

Sprint-2/2-mandatory-debug/1.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
// It will print "undefined". The 'return;' statement stops the function immediately before it even looks at 'a + b'.
4-
/* Commented out the broken code:
3+
54
function sum(a, b) {
65
return;
76
a + b;
87
}
98

109
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11-
*/
10+
1211
// =============> write your explanation here
13-
// The 'return' keyword instantly exits the function. Since nothing is attached to it, it returns 'undefined'. The 'a + b;' line is dead code that never gets executed.
1412
// Finally, correct the code to fix the problem
1513
// =============> write your new code here
16-
function sum(a, b) {
17-
return a + b;
18-
}
19-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

Sprint-2/2-mandatory-debug/2.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
// It will always print "3" for every log. The function ignores the numbers we pass in and blindly uses the global 'num' (103).
6-
/* Commented out the broken code:
5+
76
const num = 103;
87

98
function getLastDigit() {
@@ -13,22 +12,13 @@ function getLastDigit() {
1312
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1413
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1514
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16-
*/
15+
1716
// Now run the code and compare the output to your prediction
1817
// =============> write the output here
19-
// The last digit of 42 is 3
20-
// The last digit of 105 is 3
21-
// The last digit of 806 is 3
2218
// Explain why the output is the way it is
2319
// =============> write your explanation here
24-
// The function lacks a parameter in its definition. Therefore, it ignores the arguments (42, 105, 806) and always falls back to the globally defined 'num' which is 103.
2520
// Finally, correct the code to fix the problem
2621
// =============> write your new code here
27-
function getLastDigit(number) {
28-
return number.toString().slice(-1);
29-
}
30-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
22+
3323
// This program should tell the user the last digit of each number.
3424
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)