Skip to content

Commit 4e090d9

Browse files
committed
prettier
1 parent 42f5fa5 commit 4e090d9

File tree

11 files changed

+53
-49
lines changed

11 files changed

+53
-49
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Predict and explain first...
2-
// =============> write your prediction here => This code will throw a syntax error
2+
// =============> write your prediction here => This code will throw a syntax error
33
// because the parameter str is redeclared as a let variable inside the function, which is not allowed.
44

5-
6-
75
// call the function capitalise with a string input
86
// interpret the error message and figure out why an error is occurring
97

@@ -12,14 +10,13 @@
1210
// return str;
1311
// }
1412

15-
// =============> write your explanation here => The error occurs because we cannot declare
16-
// a new variable with the same name as a function parameter (str) using let inside the function.
13+
// =============> write your explanation here => The error occurs because we cannot declare
14+
// a new variable with the same name as a function parameter (str) using let inside the function.
1715
// This causes a "Identifier 'str' has already been declared" error according to mdn.
1816

19-
2017
// =============> write your new code here
2118
function capitalise(str) {
2219
return `${str[0].toUpperCase()}${str.slice(1)}`;
2320
}
2421

25-
console.log(capitalise("bethan"));
22+
console.log(capitalise("bethan"));

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

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

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
// An error will occur because 'decimalNumber' is redeclared inside the function using 'const',
6-
// which is not allowed. Also, 'decimalNumber' is not defined in the global scope,
5+
// An error will occur because 'decimalNumber' is redeclared inside the function using 'const',
6+
// which is not allowed. Also, 'decimalNumber' is not defined in the global scope,
77
// so console.log(decimalNumber) will throw a ReferenceError.
88

99
// Try playing computer with the example to work out what is going on
@@ -18,8 +18,8 @@
1818
// console.log(decimalNumber);
1919

2020
// =============> write your explanation here
21-
// The error occurs because we cannot redeclare the parameter 'decimalNumber' inside the function
22-
// using 'const'. Also, 'decimalNumber' is not defined outside the function, so
21+
// The error occurs because we cannot redeclare the parameter 'decimalNumber' inside the function
22+
// using 'const'. Also, 'decimalNumber' is not defined outside the function, so
2323
// console.log(decimalNumber) will throw a ReferenceError.
2424

2525
// Finally, correct the code to fix the problem
@@ -30,4 +30,4 @@ function convertToPercentage(decimalNumber) {
3030
return percentage;
3131
}
3232

33-
console.log(convertToPercentage(0.9)); // Output: 90%
33+
console.log(convertToPercentage(0.9)); // Output: 90%

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Predict and explain first BEFORE you run any code...
32

43
// this function should square any number but instead we're going to get an error
@@ -10,7 +9,6 @@
109
// return num * num;
1110
// }
1211

13-
1412
// =============> write the error message here
1513
// SyntaxError: Unexpected number
1614

@@ -21,7 +19,7 @@
2119

2220
// =============> write your new code here
2321
function square(num) {
24-
return num * num;
22+
return num * num;
2523
}
2624

2725
console.log(square(7));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
// The function multiply only prints the result to the console and does not return anything.
1515
// When we use multiply(10, 32) inside the template literal, it evaluates to undefined because the function has no return value.
1616

17-
1817
// Finally, correct the code to fix the problem
1918
// =============> write your new code here
2019
function multiply(a, b) {
2120
return a * b;
2221
}
2322

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ function sum(a, b) {
1818
return a + b;
1919
}
2020

21-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
21+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// The last digit of 806 is 3
99
// Because getLastDigit always uses the global variable num (103) and ignores the argument.
1010

11-
1211
// const num = 103;
1312

1413
// function getLastDigit() {

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

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

1717
function calculateBMI(weight, height) {
18-
// Calculate BMI: weight divided by height squared
19-
const bmi = weight / (Math.pow(height, 2));
20-
// Return BMI rounded to 1 decimal place
21-
return +(bmi.toFixed(1));
18+
// Calculate BMI: weight divided by height squared
19+
const bmi = weight / Math.pow(height, 2);
20+
// Return BMI rounded to 1 decimal place
21+
return +bmi.toFixed(1);
2222
}
2323

24-
console.log(calculateBMI(78, 1.72));
24+
console.log(calculateBMI(78, 1.72));

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
1717

1818
function toUpperSnakeCase(str) {
19-
// Replace spaces with underscores and convert to uppercase
20-
return str.replace(/ /g, "_").toUpperCase();
19+
// Replace spaces with underscores and convert to uppercase
20+
return str.replace(/ /g, "_").toUpperCase();
2121
}
2222

23-
2423
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
2524
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS"

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
// You should call this function a number of times to check it works for different inputs
77

88
function toPounds(penceString) {
9-
// Remove trailing 'p' and pad with zeros to ensure at least 3 digits
10-
const pence = penceString.substring(0, penceString.length - 1).padStart(3, "0");
11-
// Get pounds and pence parts
12-
const pounds = pence.substring(0, pence.length - 2);
13-
const pencePart = pence.substring(pence.length - 2).padEnd(2, "0");
14-
// Return formatted string
15-
return ${pounds}.${pencePart}`;
9+
// Remove trailing 'p' and pad with zeros to ensure at least 3 digits
10+
const pence = penceString
11+
.substring(0, penceString.length - 1)
12+
.padStart(3, "0");
13+
// Get pounds and pence parts
14+
const pounds = pence.substring(0, pence.length - 2);
15+
const pencePart = pence.substring(pence.length - 2).padEnd(2, "0");
16+
// Return formatted string
17+
return ${pounds}.${pencePart}`;
1618
}
1719

18-
19-
console.log(toPounds("399p")); // £3.99
20-
console.log(toPounds("9p")); // £0.09
21-
console.log(toPounds("99p")); // £0.99
22-
console.log(toPounds("100p")); // £1.00
23-
console.log(toPounds("1234p")); // £12.34
20+
console.log(toPounds("399p")); // £3.99
21+
console.log(toPounds("9p")); // £0.09
22+
console.log(toPounds("99p")); // £0.99
23+
console.log(toPounds("100p")); // £1.00
24+
console.log(toPounds("1234p")); // £12.34

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function formatTimeDisplay(seconds) {
2626
// =============> write your answer here
2727
// The first call is pad(totalHours). For input 61, totalHours is 0.
2828

29-
3029
// c) What is the return value of pad is called for the first time?
3130
// =============> write your answer here
3231
// pad(0) returns "00".
@@ -35,7 +34,6 @@ function formatTimeDisplay(seconds) {
3534
// =============> write your answer here
3635
// The last call is pad(remainingSeconds). For input 61, remainingSeconds is 1.
3736

38-
3937
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
4038
// =============> write your answer here
4139
// pad(1) returns "01".

0 commit comments

Comments
 (0)