File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============>
33
44// call the function capitalise with a string input
55// interpret the error message and figure out why an error is occurring
66
77function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
8+ let newStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9+ return newStr ;
1010}
1111
12+
1213// =============> write your explanation here
1314// =============> write your new code here
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Why will an error occur when this program runs?
4- // =============> write your prediction here
4+ = === === === === > write your prediction here: the error will occur because the variable decimslNumber gevine a value of 0.5
5+ with a const declaration and this will make an error if the brograme given a diffrent value for the decimalNumber .
56
67// Try playing computer with the example to work out what is going on
78
@@ -14,7 +15,18 @@ function convertToPercentage(decimalNumber) {
1415
1516console . log ( decimalNumber ) ;
1617
17- // =============> write your explanation here
18+ // =============> write your explanation here
19+ when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared . This is because the variable decimalNumber is declared twice in the function
20+ convertToPercentage , and inside the function with the constant varible CSSStyleDeclaration . also using the function name decimalNumber with the console . log function will give an error because the function name should be
21+ to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name
22+ 'ConvertToPercentage' to recall the function and pass the value of the decimalNumber . CSSStyleDeclaration
1823
1924// Finally, correct the code to fix the problem
2025// =============> write your new code here
26+ function convertToPercentage ( decimalNumber ) {
27+ const percentage = `${ decimalNumber * 100 } %` ;
28+
29+ return percentage ;
30+ }
31+
32+ console . log ( convertToPercentage ( 0.5 ) ) ;
You can’t perform that action at this time.
0 commit comments