Skip to content

Commit 5816a40

Browse files
committed
correct code 2
1 parent aa750f6 commit 5816a40

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

  • Sprint-3/1-key-errors

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

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

33
// Why will an error occur when this program runs?
4-
// / to calculate the percentage it has used the value from
5-
// convertToPercentage() function so there will be error because
6-
// the variable name for the parameter and const is the same. and console.log is called
4+
// / to calculate the percentage it has used the value from
5+
// convertToPercentage() function so there will be error because
6+
// the variable name for the parameter and const is the same. and console.log is called
77
// to print decimalNumber which is not known outside the function
88
// instead of printing the retun value of the function.
99

10-
1110
// Try playing computer with the example to work out what is going on
1211

1312
function convertToPercentage(decimalNumber) {
@@ -20,18 +19,27 @@ function convertToPercentage(decimalNumber) {
2019
console.log(decimalNumber);
2120

2221
// the error was syntaxError it is stating decimalNumber has already been declared
23-
//the parameter of the function convertToPercentage() and the const variable is the same
22+
//the parameter of the function convertToPercentage() and the const variable is the same
2423

2524
// Finally, correct the code to fix the problem
26-
// There can be two ways to fix the problem
25+
// There can be two ways to fix the problem
2726
// 1. to change const variable and the name decimalNumber in line 15.
2827
// but still need to call the function convertToPercentage() in the consol.log()
29-
28+
3029
// function convertToPercentage(decimalNumber){
31-
// const numeral = 0.5;
32-
// const percentage = `${numeral*100}%`;
33-
// return percentage;
34-
// }
35-
// console.log(convertToPercentage());
36-
37-
//
30+
// const numeral = 0.5;
31+
// const percentage = `${numeral*100}%`;
32+
// return percentage;
33+
// }
34+
// console.log(convertToPercentage());
35+
36+
//2 .The second one is to call the function with value in it.
37+
// and to keep the code as it is except change the const variable name/or delet
38+
// the const numeral with its value because there is no poin of keeping it.
39+
//
40+
// function convertToPercentage(decimalNumber){
41+
// const numeral = 0.5;
42+
// const percentage = `${decimalNumber*100}%`;
43+
// return percentage;
44+
// }
45+
// console.log(convertToPercentage());

0 commit comments

Comments
 (0)