Skip to content

Commit 878ee90

Browse files
committed
Cleanup: Reverted all Sprint-2 related code from this Sprint-3 branch.
1 parent aa82bda commit 878ee90

File tree

12 files changed

+3434
-164
lines changed

12 files changed

+3434
-164
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

7-
// function capitalise(str) {
8-
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
// return str;
10-
// }
11-
12-
// So, the error sounds "SyntaxError: Identifier 'str' has already been declared", it means that we can't declare the sane variable name twice
13-
// =============> write your new code here
147
function capitalise(str) {
15-
return `${str[0].toUpperCase()}${str.slice(1)}`;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
1610
}
1711

18-
console.log(capitalise("greetings")); // Output: "Greetings"
12+
// =============> write your explanation here
13+
// =============> write your new code here

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
// I suppose the error could be:
6-
// 1. The variable "decimalNumber" declared twice in the same scope (in the function's parameter and in the function's body)
7-
// 2. We can't reassign a value if we use word "const" to declare a variaable
8-
// 3. The variable "decimalNumber" isn't defined in the global scope, so when we try to use function console.log(decimalNumber) it will throw a ReferenceError. If we want to log the result of the function we have to call this function with some argument: console.log(convertToPercentage(0.5))
95

106
// Try playing computer with the example to work out what is going on
117

12-
// function convertToPercentage(decimalNumber) {
13-
// const decimalNumber = 0.5;
14-
// const percentage = `${decimalNumber * 100}%`;
8+
function convertToPercentage(decimalNumber) {
9+
const decimalNumber = 0.5;
10+
const percentage = `${decimalNumber * 100}%`;
1511

16-
// return percentage;
17-
// }
12+
return percentage;
13+
}
1814

19-
// console.log(decimalNumber);
15+
console.log(decimalNumber);
2016

2117
// =============> write your explanation here
22-
//So, when I run the code, I got "SyntaxError: Identifier 'decimalNumber' has already been declared" and that the same as my prediction above. I didn't think that actually we don't need to declare "decimalNumber" again inside the function, and I removed line "const decimalNumber = 0.5; to fix the problem. THen, I called the function with the argument 0.5 in console.log and this worked fine.
2318

2419
// Finally, correct the code to fix the problem
2520
// =============> write your new code here
26-
function convertToPercentage(decimalNumber) {
27-
return `${decimalNumber * 100}%`;
28-
}
29-
30-
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
@@ -1,25 +1,20 @@
1+
12
// Predict and explain first BEFORE you run any code...
23

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

56
// =============> write your prediction of the error here
6-
//I think that's an error because there is no declared variable "num".
77

8-
// function square(3) {
9-
// return num * num;
10-
// }
8+
function square(3) {
9+
return num * num;
10+
}
1111

1212
// =============> write the error message here
13-
// SyntaxError: Unexpected number
1413

1514
// =============> explain this error message here
16-
// As I can see now after running the code, I missed the very first error - we can't use a number as a parameter name, and JavaScript even didn't go after the very first mistake to check others errors (and my predicted error about undeclared "num")
1715

1816
// Finally, correct the code to fix the problem
1917

2018
// =============> write your new code here
21-
function square(num) {
22-
return num * num;
23-
}
2419

25-
console.log(square(12)); // 144
20+

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

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

3-
// =============> I think the result will be undefined because in the function there is no return statement.
3+
// =============> write your prediction here
44

5-
// function multiply(a, b) {
6-
// console.log(a * b);
7-
// }
8-
9-
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10-
11-
// =============> Its interesting - function log the result but doesn't return it. So when we see the output 320 and "undefined"
12-
13-
// Finally, correct the code to fix the problem
145
function multiply(a, b) {
15-
return a * b;
6+
console.log(a * b);
167
}
178

189
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
13+
// Finally, correct the code to fix the problem
14+
// =============> write your new code here

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// Predict and explain first...
2-
// =============> I guess that the output will be undefined because there is a semicolon after the "return" and this breaks the line of code, and after return statement nothing can be returned
2+
// =============> write your prediction here
33

4-
// function sum(a, b) {
5-
// return;
6-
// a + b;
7-
// }
8-
9-
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> The output is "The sum of 10 and 32 is undefined" as I predicted above
12-
// Finally, correct the code to fix the problem
134
function sum(a, b) {
14-
return a + b;
5+
return;
6+
a + b;
157
}
168

179
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
// Finally, correct the code to fix the problem
13+
// =============> write your new code here

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

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

33
// Predict the output of the following code:
4-
// =============> The output will be:
5-
// 1. The last digit of 42 is 3
6-
// 2. The last digit of 105 is 3
7-
// 3. The last digit of 806 is 3
8-
// Why? Because we don't pass any parameter to the function ant it always uses the variable "num", which defined in the global scope, so function has access to it and the last digit of 103 is 3.
4+
// =============> Write your prediction here
95

10-
// const num = 103;
6+
const num = 103;
117

12-
// function getLastDigit() {
13-
// return num.toString().slice(-1);
14-
// }
8+
function getLastDigit() {
9+
return num.toString().slice(-1);
10+
}
1511

16-
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
17-
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
18-
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
12+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1915

2016
// Now run the code and compare the output to your prediction
21-
// =============> The last digit of 42 is 3
22-
// The last digit of 105 is 3
23-
// The last digit of 806 is 3
17+
// =============> write the output here
2418
// Explain why the output is the way it is
25-
// =============> Because we use the global variable "num" in the function instead of passing the parameter to the function.
19+
// =============> write your explanation here
2620
// Finally, correct the code to fix the problem
21+
// =============> write your new code here
2722

28-
function getLastDigit(num) {
29-
return num.toString().slice(-1);
30-
}
31-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
32-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
33-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
34-
//
3523
// This program should tell the user the last digit of each number.
36-
//
37-
// Now output looks correctly:
38-
// The last digit of 42 is 2
39-
// The last digit of 105 is 5
40-
// The last digit of 806 is 6
41-
//
4224
// Explain why getLastDigit is not working properly - correct the problem
43-
// Actually, maybe its not the good idea to use the same name "num" for different variables in different scopes, because it can be confusing. It works correctly but next time I'll use for the global scope some more meaningful name.

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,5 @@
1515
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18-
bmi = Number((weight / height ** 2).toFixed(1));
19-
return bmi;
20-
}
21-
22-
console.log(calculateBMI(70, 1.73)); // 23.4
23-
console.log(calculateBMI(120, 1.82)); // 36.2
24-
console.log(calculateBMI(53, 1.68)); // 18.8
18+
// return the BMI of someone based off their weight and height
19+
}

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,3 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17-
18-
function toUpperSnakeCase(str) {
19-
transformedStr = str.toUpperCase().replaceAll(" ", "_");
20-
return transformedStr;
21-
}
22-
23-
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
24-
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS"
25-
console.log(toUpperSnakeCase("code your future is great")); // "CODE_YOUR_FUTURE_IS_GREAT"

Sprint-2/3-mandatory-implement/3-to-pounds.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,3 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7-
8-
function toPounds(penceStr) {
9-
const penceStrWithoutTrailingP = penceStr.substring(0, penceStr.length - 1);
10-
const paddedPenceNumberString = penceStrWithoutTrailingP.padStart(3, "0");
11-
const pounds = paddedPenceNumberString.substring(
12-
0,
13-
paddedPenceNumberString.length - 2
14-
);
15-
const pence = paddedPenceNumberString
16-
.substring(paddedPenceNumberString.length - 2)
17-
.padEnd(2, "0");
18-
19-
return ${pounds}.${pence}`;
20-
}
21-
22-
console.log(toPounds("123p")); // £1.23
23-
console.log(toPounds("1002p")); // £10.02
24-
console.log(toPounds("0p")); // £0.00
25-
console.log(toPounds("99p")); // £0.99
26-
console.log(toPounds("250p")); // £2.50
27-
console.log(toPounds("7p")); // £0.07
28-
console.log(toPounds("48p")); // £0.48
29-
console.log(toPounds("53647868p")); // £536478.68

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) {
1717
// Questions
1818

1919
// a) When formatTimeDisplay is called how many times will pad be called?
20-
// =============> 3 times
20+
// =============> write your answer here
2121

2222
// Call formatTimeDisplay with an input of 61, now answer the following:
2323

2424
// b) What is the value assigned to num when pad is called for the first time?
25-
// =============> 0
25+
// =============> write your answer here
2626

2727
// c) What is the return value of pad is called for the first time?
28-
// =============> "00"
28+
// =============> write your answer here
2929

3030
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31-
// =============> "1". The last time pad works on remainingSeconds which is "1" if the input (remainingSeconds) is 61: remainingSeconds = seconds % 60, modulo operator gives the remainder of the division of seconds by 60, so 61 % 60 = 1.
31+
// =============> write your answer here
3232

3333
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34-
// =============> "01". THe pad(1) is called, converting 1 to string and transform it to "01".
34+
// =============> write your answer here

0 commit comments

Comments
 (0)