Skip to content

Commit 9859d0d

Browse files
authored
restoring sprint 2
1 parent 2e1ae4a commit 9859d0d

File tree

11 files changed

+18
-127
lines changed

11 files changed

+18
-127
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
4-
// The code will capitalize the first word of the str which gives "Str"
53

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

9-
// The error occurs in line 13 and it says "SyntaxError: Identifier 'str' has already been declared"
10-
// The error is informing us that the string str has already been declared in line 12 so we can not declare it again.
11-
12-
//function capitalise(str) {
13-
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
14-
// return str;
15-
//}
16-
17-
// =============> write your explanation here
18-
19-
// The code is written to capitalize the first letter of str which is expected to give the result Str.
20-
21-
// =============> write your new code here
22-
237
function capitalise(str) {
24-
str = `${str[0].toUpperCase()}${str.slice(1)}`;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
259
return str;
2610
}
27-
console.log(capitalise("str"))
11+
12+
// =============> write your explanation here
13+
// =============> write your new code here

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

Lines changed: 3 additions & 13 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-
// This code is tend to be a code to convert decimal number in to %. I predict there will be an error because the call for the function has a bug.
65

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

9-
/*function convertToPercentage(decimalNumber) {
8+
function convertToPercentage(decimalNumber) {
109
const decimalNumber = 0.5;
1110
const percentage = `${decimalNumber * 100}%`;
1211

1312
return percentage;
14-
}/
13+
}
1514

16-
console.log(decimalNumber);*/
15+
console.log(decimalNumber);
1716

1817
// =============> write your explanation here
19-
// A syntaxError has been observed because the decimalNumber is already declared.
20-
// if we delete line 10 anther error happen this time about calling the function in which decimalNumber is not defined in the global scope.
2118

2219
// Finally, correct the code to fix the problem
2320
// =============> write your new code here
24-
function convertToPercentage(decimalNumber) {
25-
const percentage = `${decimalNumber * 100}%`;
26-
27-
return percentage;
28-
}
29-
30-
console.log(convertToPercentage("0.5"));

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +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-
/* There is a problem in the function parameter. we can not use number in parameter.
8-
even though line 12 by it self has no coding problem but the num is not declared before.*/
97

10-
/*
118
function square(3) {
129
return num * num;
1310
}
14-
*/
1511

1612
// =============> write the error message here
17-
/* unexpected number
13+
1814
// =============> explain this error message here
19-
we can not use number in a parameter so 3 is not used as identifier */
2015

2116
// Finally, correct the code to fix the problem
2217

2318
// =============> write your new code here
24-
function square(num) {
25-
return num * num;
26-
}
27-
console.log(square("3"))
2819

2920

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

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

33
// =============> write your prediction here
4-
/*the function doesn't return any thing so there will be an error. */
54

6-
/*function multiply(a, b) {
5+
function multiply(a, b) {
76
console.log(a * b);
87
}
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

1211
// =============> write your explanation here
13-
/* As predicted the function does not return any thing. But the first call gives 320. and the second undefine. */
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-
21-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
/* The code will give us the sum of 10 and 32 which will be " The sum of 10 and 32 is 42" */
43

5-
/*function sum(a, b) {
4+
function sum(a, b) {
65
return;
76
a + b;
87
}
98

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

1211
// =============> write your explanation here
13-
/* the call of the function gives undefine result. the reason for this is the semicolon after return which shouldn't be placed there.
1412
// Finally, correct the code to fix the problem
15-
// =============> write your new code here */
16-
function sum(a, b) {
17-
return a + b;
18-
}
19-
20-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
13+
// =============> write your new code here

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

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

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
/* I predict that the three call are giving
6-
The last digit of 42 is 2
7-
The last digit of 105 is 5
8-
The last digit of 806 is 6 */
95

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

128
function getLastDigit() {
139
return num.toString().slice(-1);
@@ -16,25 +12,13 @@ function getLastDigit() {
1612
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1713
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1814
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
19-
*/
15+
2016
// Now run the code and compare the output to your prediction
2117
// =============> write the output here
22-
/* The last digit of 42 is 3
23-
The last digit of 105 is 3
24-
The last digit of 806 is 3 */
2518
// Explain why the output is the way it is
2619
// =============> write your explanation here
27-
/* because the num is determined at fires and 103 is given to the num. as a result we see the same result.*/
2820
// Finally, correct the code to fix the problem
2921
// =============> write your new code here
3022

31-
function getLastDigit(num) {
32-
return num.toString().slice(-1);
33-
}
34-
35-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
36-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
37-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
38-
3923
// This program should tell the user the last digit of each number.
4024
// Explain why getLastDigit is not working properly - correct the problem

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

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

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

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +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-
function toUpperCase(text) {
18-
return text.toUpperCase();
19-
}
20-
21-
console.log(toUpperCase("hello there"));
22-
console.log(toUpperCase("lord of the ring"));

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +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-
function toPounds(pennies) {
8-
const pounds = pennies / 100;
9-
return pounds.toFixed(2);
10-
}
11-
12-
// calling the function to make sure it works
13-
console.log(toPounds(32391));
14-
console.log(toPounds(3239));
15-
console.log(toPounds(323));
16-
console.log(toPounds(32));
17-
console.log(toPounds(3));

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

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

1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
13-
console.log(formatTimeDisplay(61));
1413

1514
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1615
// to help you answer these questions
@@ -19,22 +18,17 @@ console.log(formatTimeDisplay(61));
1918

2019
// a) When formatTimeDisplay is called how many times will pad be called?
2120
// =============> write your answer here
22-
/* pad will be called 3 times. one for totalHours, one for remainingMinutes and one for remainingSeconds.*/
2321

2422
// Call formatTimeDisplay with an input of 61, now answer the following:
2523

2624
// b) What is the value assigned to num when pad is called for the first time?
2725
// =============> write your answer here
28-
/* when I run the code the result is 00:01:01 there for the value assigned to num is "0".
2926

3027
// c) What is the return value of pad is called for the first time?
3128
// =============> write your answer here
32-
/* the return value is "00". this comes 0 changed to string and then padstart(2,0) changes it to "00" */
3329

3430
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3531
// =============> write your answer here
36-
/* The value assigned to num when the pad is called for the last time is "1". */
3732

3833
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3934
// =============> write your answer here
40-
/* The return value is 1. The code 1.toString() changes the num 1 to string "1" then the code .padStart(2, "0"); changes "1" to "01" */

0 commit comments

Comments
 (0)