Skip to content

Commit 4a48765

Browse files
committed
done 1.js
1 parent 555b848 commit 4a48765

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Sprint-2/errors/1.js

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

3-
// Why will an error occur when this program runs?
4-
// Try playing computer with the example to work out what is going on
3+
/*
54
6-
function convertToPercentage(decimalNumber) {
7-
const decimalNumber = 0.5;
5+
Why will an error occur when this program runs?
6+
Try playing computer with the example to work out what is going on
7+
8+
1. The function won't run because we are not invoking the function,
9+
2. we have been declared one variable with const and this can not reassigned after, const decimalNumber also has a fixed value
10+
3. To work efficiently we should assign the parameter =+ inside the function and declare the var decimalNumber
11+
4. we call the function correctly with its respective argument
12+
13+
function convertToPercentage(decimalNumber) {
14+
const decimalNumber = 0.5;
15+
const percentage = `${decimalNumber * 100}%`;
16+
17+
return percentage;
18+
}
19+
20+
console.log(decimalNumber);
21+
*/
22+
23+
24+
/*================== fixed =======================*/
25+
26+
function convertToPercentage(num) {
27+
const decimalNumber = num;
828
const percentage = `${decimalNumber * 100}%`;
929

1030
return percentage;
1131
}
1232

13-
console.log(decimalNumber);
33+
console.log(convertToPercentage(.2)); //20%
34+
35+

0 commit comments

Comments
 (0)