Skip to content

Commit 3d9c508

Browse files
authored
predicting the result and correcting the error
1 parent bfedae0 commit 3d9c508

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
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" */
34

4-
function sum(a, b) {
5+
/*function sum(a, b) {
56
return;
67
a + b;
78
}
89
9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/
1011

1112
// =============> 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.
1214
// Finally, correct the code to fix the problem
13-
// =============> write your new code here
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)}`);

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
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 */
59

6-
const num = 103;
10+
/*const num = 103;
711
812
function getLastDigit() {
913
return num.toString().slice(-1);
@@ -12,13 +16,25 @@ function getLastDigit() {
1216
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1317
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1418
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15-
19+
*/
1620
// Now run the code and compare the output to your prediction
1721
// =============> 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 */
1825
// Explain why the output is the way it is
1926
// =============> 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.*/
2028
// Finally, correct the code to fix the problem
2129
// =============> write your new code here
2230

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+
2339
// This program should tell the user the last digit of each number.
2440
// Explain why getLastDigit is not working properly - correct the problem

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
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) {
17+
function calculateBMI(weight, height) {
18+
const bmi= weight/ (height*height)
19+
return bmi.toFixed(1);
1820
// return the BMI of someone based off their weight and height
19-
}
21+
}
22+
console.log(calculateBMI(86,1.70));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@
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));

0 commit comments

Comments
 (0)