Skip to content

Commit 79db8a6

Browse files
committed
task 1.js completed
1 parent bc34e0e commit 79db8a6

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// Answer below:
5+
// An error will occur for two reasons, first because there variable "decimalNumber" being decleared
6+
// The second reason is because the function "convertToPercentage" placeholder has no value when it was called
57

6-
// Try playing computer with the example to work out what is going on
8+
// =============> write your prediction here:
9+
// Answer below:
10+
// I predicted that the code will not work because of the variable (decimalNumber) inside the function,
11+
// Also because the console.log function is not not calling the function "convertToPercentage" with a value
712

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
1113

12-
return percentage;
13-
}
14+
// Try playing computer with the example to work out what is going on
15+
16+
// function convertToPercentage(decimalNumber) {
17+
// const decimalNumber = 0.5;
18+
// const percentage = `${decimalNumber * 100}%`;
1419

15-
console.log(decimalNumber);
20+
// return percentage;
21+
// }
22+
// console.log(decimalNumber);
1623

1724
// =============> write your explanation here
1825

1926
// Finally, correct the code to fix the problem
2027
// =============> write your new code here
28+
29+
function convertToPercentage(decimalNumber) {
30+
const percentage = `${decimalNumber * 100}%`;
31+
32+
return percentage;
33+
}
34+
console.log(convertToPercentage(10.5));

0 commit comments

Comments
 (0)