Skip to content

Commit 5e38349

Browse files
author
Arthur
committed
clean the accidental Sprint-2
1 parent b5540b5 commit 5e38349

8 files changed

Lines changed: 59 additions & 118 deletions

File tree

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1+
// Predict and explain first...
2+
// =============> write your prediction here
13

4+
// call the function capitalise with a string input
5+
// interpret the error message and figure out why an error is occurring
26

37
function capitalise(str) {
4-
let str = '${str[0].toUpperCase()}${str.slice(1)}`;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
59
return str;
610
}
711

8-
It said syntaxError because identifier 'str' has already been declared
9-
because we should use backtick`` to wrap the template literal.The first one of the bracket is a
10-
single quote, not a backtick.
11-
12-
Also, since str has already been declared as a parameter, we should not use it to define as variable.
13-
14-
15-
16-
17-
18-
function capitalise(str) {
19-
20-
let result = `${str[0].toUpperCase() + str.slice(1)}`;
21-
return result;
22-
}
23-
24-
console.log(capitalise("str"));
25-
12+
// =============> write your explanation here
13+
// =============> write your new code here

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
function convertToPercentage(decimalNumber) {
2-
const decimalNumber = 0.5;
3-
const percentage = `${decimalNumber * 100}%`;
4-
5-
return percentage;
6-
}
7-
8-
console.log(decimalNumber);
9-
10-
The terminal shows the syntax error because decimal number has been declared.
11-
because the decimal number is a variable which is not supposed to define in the function,
12-
but the decimal number has been defined insides the functon, so it will forever return 50 %.
13-
Also, when we call the fucnton, we should name the function convertToPercentage.
1+
// Predict and explain first...
142

3+
// Why will an error occur when this program runs?
4+
// =============> write your prediction here
155

6+
// Try playing computer with the example to work out what is going on
167

178
function convertToPercentage(decimalNumber) {
18-
9+
const decimalNumber = 0.5;
1910
const percentage = `${decimalNumber * 100}%`;
2011

2112
return percentage;
2213
}
2314

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

19+
// Finally, correct the code to fix the problem
20+
// =============> write your new code here

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11

2+
// Predict and explain first BEFORE you run any code...
23

4+
// this function should square any number but instead we're going to get an error
5+
6+
// =============> write your prediction of the error here
37

48
function square(3) {
59
return num * num;
610
}
711

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

9-
It shows the syntax error which is an unexpected number;
10-
because we should not put 3 insides the variable, because it will lead to variable: num not defined
11-
insides the function, so the 3 doesn't work insides the function.
12-
13-
We need to put num instead of 3 insides the();
14-
That way when we call the function by using console.log.The 3 will go into the num variable.
15-
14+
// =============> explain this error message here
1615

17-
function square(num) {
18-
return num * num;
19-
}
16+
// Finally, correct the code to fix the problem
2017

18+
// =============> write your new code here
2119

2220

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

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

2-
The problem is unexpected identifier "problem"
3-
The problem is the result doesn't print the mulitplication of the number,
4-
because we should not call the function inside the function;
5-
3+
// =============> write your prediction here
64

75
function multiply(a, b) {
86
console.log(a * b);
97
}
108

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

13-
Instead, we should define the expression a * b
14-
and return the expression.
15-
16-
/ function multiply(a, b) {
17-
return (a * b);
18-
}
11+
// =============> write your explanation here
1912

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

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Unexpected identifier "problem"
2-
variable hasn't been defined so the variable cannot do function.
1+
// Predict and explain first...
2+
// =============> write your prediction here
33

44
function sum(a, b) {
55
return;
@@ -8,14 +8,6 @@ function sum(a, b) {
88

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

11-
12-
because return should be followed by a + b;
13-
the final result doesn't return the value.
14-
15-
16-
function sum(a, b) {
17-
return;
18-
a + b;
19-
}
20-
21-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
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 & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
// Predict and explain first...
12

2-
The const should not be put into the global frame.
3-
if it is set in the global frame, this will result in a single result:3,
4-
no matter which variables you put in later.
5-
6-
The variable insides should have num to match the function expression.
7-
8-
9-
My prediction of the result will be all in 3.
3+
// Predict the output of the following code:
4+
// =============> Write your prediction here
105

116
const num = 103;
127

@@ -18,22 +13,12 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1813
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1914
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2015

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
2122

22-
23-
yes the output is all in 3, because the reason are above .
24-
25-
26-
27-
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
28-
29-
function getLastDigit(num) {
30-
return num.toString().slice(-1);
31-
}
32-
33-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
34-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
35-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
36-
37-
38-
After we delete the global frame and put in the variable, we see
39-
the result now shows three different digit number.
23+
// This program should tell the user the last digit of each number.
24+
// Explain why getLastDigit is not working properly - correct the problem
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
// Below are the steps for how BMI is calculated
12

3+
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
24

5+
// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:
36

4-
function calculateBMI(weight, height) {
5-
6-
let newheight = height / 100;
7-
let num = weight / (newheight ** 2);
8-
let idea = num.toFixed(1);
9-
10-
return idea;
11-
}
12-
13-
14-
console.log(calculateBMI(58, 178));
15-
16-
17-
7+
// squaring your height: 1.73 x 1.73 = 2.99
8+
// dividing 70 by 2.99 = 23.41
9+
// Your result will be displayed to 1 decimal place, for example 23.4.
1810

11+
// You will need to implement a function that calculates the BMI of someone based off their weight and height
1912

13+
// Given someone's weight in kg and height in metres
14+
// Then when we call this function with the weight and height
15+
// It should return their Body Mass Index to 1 decimal place
2016

17+
function calculateBMI(weight, height) {
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces.
55

66
// Implement a function that:
7-
function convertToUpperCase(text) {
8-
const result = text.toUpperCase();
9-
return result;
10-
}
11-
12-
console.log(convertToUpperCase("hello"));
13-
14-
15-
16-
177

188
// Given a string input like "hello there"
199
// When we call this function with the input string

0 commit comments

Comments
 (0)