Skip to content

Commit 3f018a2

Browse files
committed
Merge branch 'Coursework-3' of https://github.com/ausiejute/Module-JavaScript-Fundamentals into Coursework-3
2 parents d14629e + 3f9358c commit 3f018a2

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎Sprint-3/1-key-errors/1.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
// Try playing computer with the example to work out what is going on
1010

11-
/*function convertToPercentage(decimalNumber) {
11+
/* function convertToPercentage(decimalNumber) {
1212
const decimalNumber = 0.5;
1313
const percentage = `${decimalNumber * 100}%`;
1414
1515
return percentage;
1616
}
1717
*/
1818
// =============> write your explanation here
19-
//
2019

2120
// Finally, correct the code to fix the problem
2221
// =============> write your new code here

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

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

3-
// =============> write your prediction here
3+
// =============>
4+
// Variables haven't been declared, so it will throw a reference error
45

56
function multiply(a, b) {
67
console.log(a * b);
@@ -9,6 +10,13 @@ function multiply(a, b) {
910
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

1112
// =============> write your explanation here
12-
13+
// It printed 32 because that particular console function is inside the multiply function (local), whereas the other one
14+
// is outside the scope and when we call the multiply function it comes up as undefined because nothing has been returned
15+
// inside of it.
1316
// Finally, correct the code to fix the problem
1417
// =============> write your new code here
18+
19+
/* function multiply(a, b) {
20+
return a * b;
21+
}
22+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); */

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// it will print the following: `The sum of 10 and 32 is undefined'
34

5+
/*
46
function sum(a, b) {
57
return;
68
a + b;
79
}
810
911
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
12+
*/
1013

1114
// =============> write your explanation here
15+
// the function sum doesn't return any value. The arithmetic operation doesn't execute because it's defined after 'return'
1216
// Finally, correct the code to fix the problem
1317
// =============> write your new code here
18+
function sum(a, b) {
19+
return a + b;
20+
}
21+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

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

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
6-
const num = 103;
5+
// it will not print the correct last digits
6+
/*const num = 103;
77
88
function getLastDigit() {
99
return num.toString().slice(-1);
@@ -12,13 +12,29 @@ function getLastDigit() {
1212
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1313
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15+
*/
1516

1617
// Now run the code and compare the output to your prediction
1718
// =============> 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
22+
*/
1823
// Explain why the output is the way it is
1924
// =============> write your explanation here
25+
26+
// Because the method uses the num value which is 103.
2027
// Finally, correct the code to fix the problem
2128
// =============> write your new code here
2229

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+
2338
// This program should tell the user the last digit of each number.
2439
// Explain why getLastDigit is not working properly - correct the problem
40+
// The function getLastDigit wasn't using intended parameters

0 commit comments

Comments
 (0)