File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed
Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change 22// =============> write your prediction here
33
44// call the function capitalise with a string input
5+
56// interpret the error message and figure out why an error is occurring
67
78function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
9+ let outputStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
10+ console . log ( outputStr ) ;
11+ return outputStr ;
1012}
13+ capitalise ( "edak" ) ;
1114
1215// =============> write your explanation here
16+
17+ //expecting the function to return the characters of the string, with the first character capitalized.
18+
19+ //syntaxError: Identifier 'str' has already been declared.
20+ // The variable str has already been passed as parameter in the function (), declaring it again cause an identity error
21+
1322// =============> write your new code here
23+
24+ // function capitalise(str) {
25+ // let outputStr = `${str[0].toUpperCase()}${str.slice(1)}`;
26+ // console.log(outputStr);
27+ // return outputStr;
28+ //};
29+ //capitalise('edak')
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
54
5+ // =============> write your prediction here
6+ // decimalNumber is supplied as a function parameter and and also declared as a variable,
7+ // it will throw an identifier syntaxError.
68// Try playing computer with the example to work out what is going on
79
810function convertToPercentage ( decimalNumber ) {
@@ -15,6 +17,15 @@ function convertToPercentage(decimalNumber) {
1517console . log ( decimalNumber ) ;
1618
1719// =============> write your explanation here
18-
20+ // playing computer with the first code throw syntaxError: decimalNumber has been already declared.
1921// Finally, correct the code to fix the problem
22+
2023// =============> write your new code here
24+
25+ function convertToPercentage ( decimalNumber ) {
26+ // const decimalNumber = 0.5;
27+ const percentage = `${ decimalNumber * 100 } %` ;
28+ return percentage ;
29+ }
30+
31+ console . log ( convertToPercentage ( 0.5 ) ) ;
Original file line number Diff line number Diff line change 11
22// Predict and explain first BEFORE you run any code...
3+ //This code is to take one number function parameter and return area.
34
45// this function should square any number but instead we're going to get an error
56
6- // =============> write your prediction of the error here
7+ // =============> write your prediction of the error here.
8+ // syntaxError: passing an argument instead for a parameter.
79
810function square ( 3 ) {
911 return num * num ;
1012}
1113
1214// =============> write the error message here
15+ //SyntaxError:Unexpected number
1316
1417// =============> explain this error message here
18+ //The function was not expecting number during declaration
1519
1620// Finally, correct the code to fix the problem
1721
18- // =============> write your new code here
1922
23+ // =============> write your new code here
2024
25+ //function square(num) {
26+ // return num * num;
27+ //}
28+ //console.log(square(3))
You can’t perform that action at this time.
0 commit comments