Skip to content

Commit c57d664

Browse files
committed
restore sprint-2 from origin/main
1 parent e4ba658 commit c57d664

File tree

11 files changed

+45
-172
lines changed

11 files changed

+45
-172
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
// Predict and explain first...
2-
// =============> I predict that we will not need to write let in line 8 as str is already declared
3-
// as an argument within the function captialise.
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-
// capitalise ('hello');
14-
//==============> A syntaxError occurred as 'str' is being cleared.
15-
16-
177
function capitalise(str) {
18-
str = `${str[0].toUpperCase()}${str.slice(1)}`;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
199
return str;
2010
}
21-
console.log (capitalise ('hello'));
22-
2311

12+
// =============> write your explanation here
13+
// =============> write your new code here

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

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

33
// Why will an error occur when this program runs?
4-
// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement.
5-
// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage.
4+
// =============> write your prediction here
65

76
// Try playing computer with the example to work out what is going on
87

9-
// function convertToPercentage(decimalNumber) {
10-
// const decimalNumber = 0.5;
11-
// const percentage = `${decimalNumber * 100}%`;
12-
13-
// return percentage;
14-
//}
15-
16-
// console.log(decimalNumber);
17-
18-
// =============> A syntaxError occurred saying decimalNumber is already declared.
19-
20-
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
22-
23-
function convertToPercentage() {
8+
function convertToPercentage(decimalNumber) {
249
const decimalNumber = 0.5;
2510
const percentage = `${decimalNumber * 100}%`;
2611

2712
return percentage;
2813
}
2914

30-
console.log(convertToPercentage());
15+
console.log(decimalNumber);
16+
17+
// =============> write your explanation here
3118

32-
// the new code runs without error and outputs "50%"
19+
// Finally, correct the code to fix the problem
20+
// =============> write your new code here

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33

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

6-
// =============> The num parameter should be mentioned inside the function square instead of the number 3.
7-
// then it should be called as square (3) in the console.log statement.
6+
// =============> write your prediction of the error here
87

9-
//function square(3) {
10-
//return num * num;
11-
//}
12-
13-
// =============> function square(3) syntaxError: Unexpected number.
14-
// =============> 3 wasn't expected... instead a declaration like 'num' was expected.
8+
function square(3) {
9+
return num * num;
10+
}
1511

12+
// =============> write the error message here
1613

14+
// =============> explain this error message here
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-
}
24-
25-
console.log(square(3));
2619

2720

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

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

3-
// =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better
4-
//because the console.log would only print a*b.
3+
// =============> write your prediction here
54

6-
//function multiply(a, b) {
7-
//console.log(a * b);
8-
//}
5+
function multiply(a, b) {
6+
console.log(a * b);
7+
}
98

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

12-
// =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined'
13-
// as the multiply parameters weren't considered as parameters inside the function multiply.
11+
// =============> write your explanation here
1412

1513
// Finally, correct the code to fix the problem
1614
// =============> write your new code here
17-
function multiply(a, b) {
18-
return a * b;
19-
}
20-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Predict and explain first...
2-
// =============> SyntaxError will occur due to putting a semicolon after return.
2+
// =============> write your prediction here
33

44
function sum(a, b) {
5-
return a + b;
5+
return;
6+
a + b;
67
}
78

89
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
910

10-
// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'.
11+
// =============> write your explanation here
1112
// Finally, correct the code to fix the problem
1213
// =============> write your new code here
13-
// we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return.

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

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

33
// Predict the output of the following code:
4-
// =============> The code will return 3 as a string first, but after calling the getLastDigit function,
5-
// it will not return anything because every number based will be converted to string.
4+
// =============> Write your prediction here
65

7-
//const num = 103;
6+
const num = 103;
87

9-
//function getLastDigit() {
10-
// return num.toString().slice(-1);
11-
//}
12-
13-
//console.log(`The last digit of 42 is ${getLastDigit(42)}`);
14-
//console.log(`The last digit of 105 is ${getLastDigit(105)}`);
15-
//console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16-
17-
// Now run the code and compare the output to your prediction
18-
// =============> The last digit of 42 is 3 three times.
19-
// the prediction was close but not accurate, the case is that the parameter num needs to be
20-
//the function instead of const num = 103.
21-
// =============>
22-
// Finally, correct the code to fix the problem
23-
// =============> write your new code here
24-
25-
function getLastDigit(num) {
8+
function getLastDigit() {
269
return num.toString().slice(-1);
2710
}
2811

2912
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
3013
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
3114
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15+
16+
// Now run the code and compare the output to your prediction
17+
// =============> write the output here
18+
// Explain why the output is the way it is
19+
// =============> write your explanation here
20+
// Finally, correct the code to fix the problem
21+
// =============> write your new code here
22+
3223
// This program should tell the user the last digit of each number.
3324
// Explain why getLastDigit is not working properly - correct the problem
34-
// parameter num needs to be with the getLastDigit function instead of const num=103.

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

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

1717
function calculateBMI(weight, height) {
18-
const bmi = weight / (weight*height);
19-
return bmi.toFixed(1);
2018
// return the BMI of someone based off their weight and height
21-
}
22-
console.log("the BMI is", calculateBMI(70, 1.73));
19+
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +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 capSnakeCase(str) {
19-
const upper = str.toUpperCase();
20-
const snake = upper.replace(/ /g, "_");
21-
return snake;
22-
}
23-
console.log(capSnakeCase("lord of the rings"));
24-
25-
// step 1: get a string input
26-
//step 2: change the upper case
27-
//step 3: replace spaces with underscores
28-
// step 4: return capSnakeCase

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +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 (penceString){
9-
const penceStringWithoutTrailingP = penceString.substring(0, penceString. length -1);
10-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart (3, "0");
11-
const pounds = paddedPenceNumberString.substring (0,paddedPenceNumberString.length -2);
12-
const pence = paddedPenceNumberString.substring (paddedPenceNumberString.length -2); padEnd(2,"0");
13-
14-
return ${pounds}.${pence}`;
15-
}
16-
console.log(toPounds("399p"))
17-
console.log(toPounds("5p"))
18-
console.log(toPounds("5678p"))

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ function formatTimeDisplay(seconds) {
1010

1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
13-
console.log(formatTimeDisplay(61));
13+
1414
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1515
// to help you answer these questions
1616

1717
// Questions
1818

1919
// a) When formatTimeDisplay is called how many times will pad be called?
20-
// =============> It will be called 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-
// =============> The leftover second is assigned to num as remainingSEconds 61%60
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 remainingSeconds from passed from pad to num is changed to string and padded as 01
34+
// =============> write your answer here

0 commit comments

Comments
 (0)