Skip to content

Commit 60be8e2

Browse files
committed
Remove Prettier changes from 5-stretch exercise
1 parent 62e622c commit 60be8e2

10 files changed

Lines changed: 59 additions & 71 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
//- we expect a syntaxerror because "str" is already declared as function parameter and again as a variable within the same function scope.
3+
//- we expect a syntaxerror because "str" is already declared as function parameter and again as a variable within the same function scope.
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
6-
//"Error: SyntaxError: Identifier 'str' has already been declared" why: because "str" declared twice.
6+
//"Error: SyntaxError: Identifier 'str' has already been declared" why: because "str" declared twice.
77

88
// function capitalise(str) {
99
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
@@ -16,4 +16,4 @@
1616
function capitalise(str) {
1717
return `${str[0].toUpperCase()}${str.slice(1)}`;
1818
}
19-
console.log(capitalise("abakar"));
19+
console.log(capitalise("abakar"));

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

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

33
// Why will an error occur when this program runs?
4-
//- variable name "decimalNumber" declared twice in the same function. one as function parameter and again as a const in the same function.
4+
//- variable name "decimalNumber" declared twice in the same function. one as function parameter and again as a const in the same function.
55
// =============> write your prediction here
6-
//- SyntaxError because "decimalNumber" declared twice.
6+
//- SyntaxError because "decimalNumber" declared twice.
77
// Try playing computer with the example to work out what is going on
88

99
// function convertToPercentage(decimalNumber) {
@@ -16,17 +16,14 @@
1616
// console.log(decimalNumber);
1717

1818
// =============> write your explanation here
19-
// I removed the separate decimalNumber variable because the function already accepts decimalNumber as a parameter. I can now pass a number directly when calling the function, such as convertToPercentage(7). The function multiplies the value by 100 and appends % to return the percentage.
19+
// I removed the separate decimalNumber variable because the function already accepts decimalNumber as a parameter. I can now pass a number directly when calling the function, such as convertToPercentage(7). The function multiplies the value by 100 and appends % to return the percentage.
2020

2121
// =============> write your new code here
2222

23-
2423
function convertToPercentage(decimalNumber) {
25-
2624
const percentage = `${decimalNumber * 100}%`;
2725

2826
return percentage;
2927
}
3028

3129
console.log(convertToPercentage(7));
32-

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
21
// Predict and explain first BEFORE you run any code...
3-
2+
43
// this function should square any number but instead we're going to get an error
5-
//we are giving a value for the input instead of name that can hold different values.
4+
//we are giving a value for the input instead of name that can hold different values.
65

76
// =============> write your prediction of the error here
8-
//syntaxerror related to the function input "(3)"
7+
//syntaxerror related to the function input "(3)"
98

109
// function square(3) {
1110
// return num * num;
@@ -14,14 +13,13 @@
1413
// =============> write the error message here
1514
// SyntaxError: Unexpected number
1615
// =============> explain this error message here
17-
// we gave a placeholder for the function instead of value that can't be changed.
16+
// we gave a placeholder for the function instead of value that can't be changed.
1817
// Finally, correct the code to fix the problem
1918

2019
// =============> write your new code here
2120

22-
2321
function square(num) {
24-
return num * num;
22+
return num * num;
2523
}
2624

27-
console.log(square(3));
25+
console.log(square(3));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
//- "a and b" are defined as parameters and receive 10 and 32. The function calculates and logs 320, but it doesn't return the value. Because there is no return, the function call evaluates to undefined.
3+
//- "a and b" are defined as parameters and receive 10 and 32. The function calculates and logs 320, but it doesn't return the value. Because there is no return, the function call evaluates to undefined.
44

5-
// function multiply(a, b) {
5+
// function multiply(a, b) {
66
// console.log(a * b);
77
// }
88

99
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

1111
// =============> write your explanation here
12-
//- Added a return statement so the function returns the result to the function call. The console.log() is just printing 320 and function doesn't give 320 back and thats why "${multiply(10, 32)}" gets undefined.
12+
//- Added a return statement so the function returns the result to the function call. The console.log() is just printing 320 and function doesn't give 320 back and thats why "${multiply(10, 32)}" gets undefined.
1313

1414
// Finally, correct the code to fix the problem
1515
// =============> write your new code here
1616

1717
function multiply(a, b) {
18-
return a * b;
18+
return a * b;
1919
}
2020

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
//- return statement in this case stops before it can do the sum of a + b.
3+
//- return statement in this case stops before it can do the sum of a + b.
44

55
// function sum(a, b) {
66
// return;
@@ -10,7 +10,7 @@
1010
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1111

1212
// =============> write your explanation here
13-
//- added a + b to return so function returns the sum.
13+
//- added a + b to return so function returns the sum.
1414
// Finally, correct the code to fix the problem
1515
// =============> write your new code here
1616

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

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

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
//-getting the last digit of 103
5+
//-getting the last digit of 103
66

7-
// const num = 103;
7+
// const num = 103;
88

99
// function getLastDigit() {
1010
// return num.toString().slice(-1);
@@ -16,29 +16,24 @@
1616

1717
// Now run the code and compare the output to your prediction
1818
// =============> 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
19+
//-The last digit of 42 is 3
20+
//-The last digit of 105 is 3
21+
//-The last digit of 806 is 3
2222

2323
// Explain why the output is the way it is
24-
// -Every time the function calls 103
24+
// -Every time the function calls 103
2525
// =============> write your explanation here
2626
// Finally, correct the code to fix the problem
2727
// =============> write your new code here
2828

2929
// This program should tell the user the last digit of each number.
3030
// Explain why getLastDigit is not working properly - correct the problem
31-
//-I removed the unnecessary const num = 103 because the function already receives num as a parameter.
32-
//-The function calculates something and returns it then console.log outside receives that returned value and prints it.
33-
34-
31+
//-I removed the unnecessary const num = 103 because the function already receives num as a parameter.
32+
//-The function calculates something and returns it then console.log outside receives that returned value and prints it.
3533

3634
function getLastDigit(num) {
3735
return num.toString().slice(-1);
38-
3936
}
4037
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
4138
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
4239
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
43-
44-

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
// Then when we call this function with the weight and height
1515
// It should return a string of their Body Mass Index to 1 decimal place
1616

17-
1817
function calculateBMI(weight, height) {
19-
const bmi= weight / (height * height);
18+
const bmi = weight / (height * height);
2019
return bmi.toFixed(1);
21-
22-
// return the BMI of someone based off their weight and height
23-
}
2420

25-
console.log(`Your BMI is ${calculateBMI(70, 1.73)}, based on your weight and height`);
21+
// return the BMI of someone based off their weight and height
22+
}
2623

24+
console.log(
25+
`Your BMI is ${calculateBMI(70, 1.73)}, based on your weight and height`,
26+
);

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

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

1818
function toUpperSnakeCase(sentence) {
19-
return sentence.toUpperCase().replaceAll(" ", "_");
20-
19+
return sentence.toUpperCase().replaceAll(" ", "_");
2120
}
22-
console.log(toUpperSnakeCase("welcome to Chad"));
21+
console.log(toUpperSnakeCase("welcome to Chad"));

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@
55

66
// You should call this function a number of times to check it works for different inputs
77

8-
function toPounds(penceString) {
9-
10-
const penceStringWithoutTrailingP = penceString.substring(
11-
0,
12-
penceString.length - 1
13-
);
14-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15-
const pounds = paddedPenceNumberString.substring(
16-
0,
17-
paddedPenceNumberString.length - 2
18-
);
8+
function toPounds(penceString) {
9+
const penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1,
12+
);
13+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
14+
const pounds = paddedPenceNumberString.substring(
15+
0,
16+
paddedPenceNumberString.length - 2,
17+
);
1918
const pence = paddedPenceNumberString
20-
.substring(paddedPenceNumberString.length - 2)
21-
.padEnd(2, "0");
19+
.substring(paddedPenceNumberString.length - 2)
20+
.padEnd(2, "0");
2221

23-
return (`£${pounds}.${pence}`);
24-
}
22+
return `£${pounds}.${pence}`;
23+
}
2524

26-
console.log(toPounds("399p"));
27-
console.log(toPounds("4000p"));
28-
console.log(toPounds("39p"));
29-
console.log(toPounds("3p"));
25+
console.log(toPounds("399p"));
26+
console.log(toPounds("4000p"));
27+
console.log(toPounds("39p"));
28+
console.log(toPounds("3p"));

‎Sprint-3/4-mandatory-interpret/time-format.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ console.log(formatTimeDisplay());
2222

2323
// a) When formatTimeDisplay is called how many times will pad be called?
2424
// =============> write your answer here
25-
//- 3 times
25+
//- 3 times
2626
// Call formatTimeDisplay with an input of 61, now answer the following:
27-
// b) What is the value assigned to num when pad is called for the first time?
28-
//- 0
27+
// b) What is the value assigned to num when pad is called for the first time?
28+
//- 0
2929

3030
// c) What is the return value of pad when it is called for the first time?
3131
// =============> write your answer here
32-
//- "00"
32+
//- "00"
3333
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3434
// =============> write your answer here
35-
//- 1, remainingSeconds is 1 because 61 % 60 = 1. The last call is pad(remainingSeconds) so pad(1) makes num = 1.
35+
//- 1, remainingSeconds is 1 because 61 % 60 = 1. The last call is pad(remainingSeconds) so pad(1) makes num = 1.
3636

3737
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3838
// =============> write your answer here
39-
//- "01" , num.toString() changes 1 into "1". Since "1" has only 1 character, the while loop adds "0" in front, making "01".
39+
//- "01" , num.toString() changes 1 into "1". Since "1" has only 1 character, the while loop adds "0" in front, making "01".

0 commit comments

Comments
 (0)