File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3-
43// Why will an error occur when this program runs?
54// =============> write your prediction here
65
7- //1- The function is trying to declare the decimalNumber twice in the perameter and later as a new variable
8- //2-console.log() is printing a variable in the local scope where it can't be accessed as it is inside the function
6+ //1- The function is trying to declare the decimalNumber twice in the perameter and later as a new variable
7+ //2-console.log() is printing a variable in the local scope where it can't be accessed as it is inside the function
98
109// Try playing computer with the example to work out what is going on
1110
1615// return percentage;
1716// }
1817
19-
20-
21-
2218// =============> write your explanation here
2319/* The variable decimal Number has already been declared in the parameter
24- and already is a local variable which can't be declared again causing a ReferenceError
20+ and already is a local variable which can't be declared again causing a SyntaxError
2521As the decimalNumber inside the function we can't print it using the console.log() as it has no power to the local scope
2622instead we can delete the second declaration and just leave the parameter as an input for the user
2723 Finally, correct the code to fix the problem */
2824
2925// =============> write your new code here
3026function convertToPercentage ( decimalNumber ) {
3127 const percentage = `${ decimalNumber * 100 } %` ;
32- return percentage ;
28+ return percentage ;
3329}
3430
3531console . log ( convertToPercentage ( 0.5 ) ) ;
Original file line number Diff line number Diff line change 1414// You will need to come up with an appropriate name for the function
1515// Use the MDN string documentation to help you find a solution
1616// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17- function toUpperSnakeFormat ( string ) {
18- return string . toUpperCase ( ) . replaceAll ( " " , "_" )
19-
17+ function toUpperSnakeFormat ( string ) {
18+ return string . toUpperCase ( ) . replaceAll ( " " , "_" ) ;
2019}
21- console . log ( toUpperSnakeFormat ( "hello there" ) )
22- console . log ( toUpperSnakeFormat ( "lord of the rings" ) )
20+ console . log ( toUpperSnakeFormat ( "hello there" ) ) ;
21+ console . log ( toUpperSnakeFormat ( "lord of the rings" ) ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function formatTimeDisplay(seconds) {
1515 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1616}
1717
18- console . log ( formatTimeDisplay ( 61 ) )
18+ console . log ( formatTimeDisplay ( 61 ) ) ;
1919// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
2020// to help you answer these questions
2121
@@ -32,11 +32,10 @@ console.log(formatTimeDisplay(61))
3232// c) What is the return value of pad is called for the first time?
3333// =============> "00"
3434
35-
3635// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3736// =============> "1"
3837// the last time, pad() is called with the remaining seconds which is value "1"
3938
4039// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
4140// =============> "01"
42- // the return value is 1 put as we are using pad wouldbe adding leading "0"
41+ // the return value is 1 put as we are using pad would be adding leading "0"
You can’t perform that action at this time.
0 commit comments