Skip to content

Commit d58e208

Browse files
fix error
1 parent d3ca5ad commit d58e208

13 files changed

Lines changed: 38 additions & 139 deletions

File tree

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,10 @@
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

7-
//////// error code /////
8-
9-
// function capitalise(str) {
10-
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11-
// return str;
12-
// }
13-
14-
// fix code //
157
function capitalise(str) {
16-
let string = `${str[0].toUpperCase()}${str.slice(1)}`;
17-
return string;
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
1810
}
19-
console.log(capitalise("hello js error"));
2011

2112
// =============> write your explanation here
2213
// =============> write your new code here
23-
24-
// The Error was syntax error as "str" has already been declared and we can't declare it again as variable name. Now I declare a new variable name and assign value.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
55

6-
// There will be two errors, First syntax errors as decimalNumber has already been declared and tried to redeclare it again inside function.
7-
// second without defining decimalNumber try to use decimalNumber in log.
8-
96
// Try playing computer with the example to work out what is going on
107

118
function convertToPercentage(decimalNumber) {
9+
const decimalNumber = 0.5;
1210
const percentage = `${decimalNumber * 100}%`;
1311

1412
return percentage;
1513
}
1614

17-
console.log(convertToPercentage(0.9));
15+
console.log(decimalNumber);
1816

1917
// =============> write your explanation here
2018

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// Predict and explain first BEFORE you run any code...
3+
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
7+
8+
function square(3) {
9+
return num * num;
10+
}
11+
12+
// =============> write the error message here
13+
14+
// =============> explain this error message here
15+
16+
// Finally, correct the code to fix the problem
17+
18+
// =============> write your new code here
19+
20+

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
12
// Predict and explain first BEFORE you run any code...
23

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

56
// =============> write your prediction of the error here
67

78
function square(3) {
8-
return num * num;
9+
return num * num;
910
}
1011

1112
// =============> write the error message here
12-
// SyntaxError: Unexpected number
1313

1414
// =============> explain this error message here
15-
// syntax error as function does not allow actual value as a parameter
1615

1716
// Finally, correct the code to fix the problem
1817

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

21-
function square(num) {
22-
return num * num;
23-
}
24-
console.log(square(2));
20+

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,5 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

1111
// =============> write your explanation here
1212

13-
// first log will show result by multiplying but second log will not show any result instead will show undefined because we did not say the code
14-
// what to do and what should return.
15-
1613
// Finally, correct the code to fix the problem
1714
// =============> write your new code here
18-
19-
function multiply(a, b) {
20-
return a * b;
21-
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
33

4-
// It will show undefined
5-
64
function sum(a, b) {
75
return;
86
a + b;
@@ -11,11 +9,5 @@ function sum(a, b) {
119
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1210

1311
// =============> write your explanation here
14-
// the reason is that I did not write anything inside return that's why return can't find anything to return
15-
1612
// Finally, correct the code to fix the problem
1713
// =============> write your new code here
18-
19-
function sum(a, b) {
20-
return a + b;
21-
}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
// I predicted that it will show undefined or fixed number like 3
65

76
const num = 103;
87

@@ -16,24 +15,10 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1615

1716
// Now run the code and compare the output to your prediction
1817
// =============> 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
2218
// Explain why the output is the way it is
23-
// num has fix number which is 3 and i return this fix number
2419
// =============> write your explanation here
25-
// user want last digit whatever number they put but i set up a fix number which will return that one that's why now i removed fixed number and wrote a parameter in function
26-
// which will contain user number whatever number they put and get the last digit.
2720
// Finally, correct the code to fix the problem
2821
// =============> write your new code here
2922

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

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

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

1717
function calculateBMI(weight, height) {
18-
let allHeight = Number(height * height);
19-
let heightWeight = Number(weight / allHeight);
20-
let oneDecimal = heightWeight.toFixed(1);
21-
return oneDecimal;
22-
23-
// return the BMI of someone based off their weight and height
24-
}
25-
console.log(calculateBMI(78, 1.77));
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 & 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-
18-
function UpperSnake(string) {
19-
let upper = string.toUpperCase().split(" ").join("_");
20-
return upper;
21-
}
22-
console.log(UpperSnake("hello py"));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// In Sprint-1, there is a program written in interpret/to-pounds.js
2+
3+
// You will need to take this code and turn it into a reusable block of code.
4+
// You will need to declare a function called toPounds with an appropriately named parameter.
5+
6+
// You should call this function a number of times to check it works for different inputs

0 commit comments

Comments
 (0)