diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..70fa5c7c1 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + +//= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. +//In this question, variable "count" changed from 0 to 1. diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..0af5287dd 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,7 @@ const lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -const initials = ``; +const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn +console.log(initials); diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..1aa19f329 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -11,13 +11,15 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); +const base = filePath.slice(lastSlashIndex); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".") + 1); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +console.log(ext); + +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..c66d73d8d 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +console.log(num); + +//math.floor is round down the number returns to largest integer less than or equal to a given number. +//math.random() could generate the number from 0 to <1 b random. +//maximum refer to 100 and minimum refer to 1. +//The calculation of num is different everytime because of math.random(). smallest value of num is 1. And largest is 100. diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..565030121 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? + +//adding // before the lines. diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..0a30f0492 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,9 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +console.log(age); + +//The error is "Assignment to constant variable." Constant value could not be alternated. +//if line 3 const changed to let the code could be executed. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..acebcee09 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,8 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + +//Initiation should access before the declaration. +//error message: Error: ReferenceError: Cannot access 'cityOfBirth' before initialization diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..7625740fa 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,7 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +9,8 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +//slice is for text or array only. Need to change card number from number to text. use toString() to convert cardNumber +//from integer to string. + +//error message: TypeError: cardNumber.slice is not a function diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..a9713c54f 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; + +//integer and number could not start for the initiation. +//SyntaxError: Invalid or unexpected token - print before modified the initiation. diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..702572043 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +12,23 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made +//A: 5 +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +//console.log(`The percentage change is ${percentageChange}`); // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +//A: line 5. there should add , between "," and "" to divided 2 conditions. // c) Identify all the lines that are variable reassignment statements +//A: carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations +//const priceDifference = carPrice - priceAfterOneYear; +//const percentageChange = (priceDifference / carPrice) * 100; +//let carPrice = "10,000"; +//let priceAfterOneYear = "8,543"; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//A: replacing , with empty string. number() is convert text to number. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..7e03bcbb4 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,23 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// A: 6 // b) How many function calls are there? +//A: 1 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % operate the remainder of 2 numbers divided. In this case, remainingSecond is the remainder of 8784 second (movieLength) +// divided 60. And the remainingSecond is 24. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//A: totalMinutes get the result form movieLength (8784) minus remainingSecond (24). The result is 8760. +//The totalMinutes is 8760 divide 60 = 146. // e) What do you think the variable result represents? Can you think of a better name for this variable? +//A: Duration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Only integer and positive value could work. If movieLength changed to negative value and decimal value, result could +// not show in correct time format. diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..cf2e0a352 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,13 +2,13 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString @@ -25,3 +25,11 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = "399": returning with shorten less index to erase p +// 3. const paddedPenceNumberString = "399"; It pads the string with the given length with specific string. +// In this case, penceStringWithoutTrailingP (399) is already with 3 digis, so no change. +// 4. const pounds = "3", getting part of the string by subString and target to get the string without last 2 digis. +// 5. const pence = "99", subString indexStart counted by length of paddedPenceNumberString - 2 that is 1. So the result of +//subString is 99. padEnd result the string with given length from the end of String. "99" length is 2 and already match +//with the function. no change. +//6. console.log = £3.99. The number refer to pounds and pence. diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..f2ea5519c 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -8,8 +8,11 @@ Let's try an example. In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; What effect does calling the `alert` function have? +A: The dialogue box come out with an optional message. Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? What is the return value of `prompt`? +A: There have a dialogue box appear and able to submit information. +After submit the information (Name). The information submitted to server. diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..d0a82a098 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -5,12 +5,98 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +A: ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? +A: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` +A: 'object' Answer the following questions: What does `console` store? +A: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +assert +: +ƒ assert() +clear +: +ƒ clear() +context +: +ƒ context() +count +: +ƒ count() +countReset +: +ƒ countReset() +createTask +: +ƒ createTask() +debug +: +ƒ debug() +dir +: +ƒ dir() +dirxml +: +ƒ dirxml() +error +: +ƒ error() +group +: +ƒ group() +groupCollapsed +: +ƒ groupCollapsed() +groupEnd +: +ƒ groupEnd() +info +: +ƒ info() +log +: +ƒ log() +memory +: +MemoryInfo {totalJSHeapSize: 12700000, usedJSHeapSize: 11200000, jsHeapSizeLimit: 3760000000} +profile +: +ƒ profile() +profileEnd +: +ƒ profileEnd() +table +: +ƒ table() +time +: +ƒ time() +timeEnd +: +ƒ timeEnd() +timeLog +: +ƒ timeLog() +timeStamp +: +ƒ timeStamp() +trace +: +ƒ trace() +warn +: +ƒ warn() +Symbol(Symbol.toStringTag) +: +"console" +[[Prototype]] +: +Object What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +A:log and assert are the functions under object "console". '.' mean calling for function. diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..5c67fecee 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,22 @@ // Predict and explain first... // =============> write your prediction here +// when user input the string. First index will be capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +//} + +// =============> write your explanation here +// SyntaxError: Identifier 'str' has already been declared. "str" has been declared in function. In the local scope of original code, str declared again. +//It caused the problem of redeclaration. Delete the "let" in local scope +// =============> write your new code here function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("roger")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..64cc0dbae 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,19 +2,31 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. +// To print the code, the code should be console.log(decimalNumber) // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +//function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; -console.log(decimalNumber); +//console.log(decimalNumber); // =============> write your explanation here +// In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to +//'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber' +//finally console.log(convertToPercentage(0.5)) should be used to print the function. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = `${decimalNumber * 100}%`; + + return decimalNumber; +} + +console.log(convertToPercentage(0.5)); diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..290e0656c 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,25 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// The code in local scope could not refer to variable. function square should attach with a variable instead of value. -function square(3) { - return num * num; -} +//function square(3) { +// return num * num; +//} // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// =============> the error caused by the wrong input for the variable "square(3)". // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..80fe37046 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,23 @@ // Predict and explain first... // =============> write your prediction here +// A: The result of multiplying 10 and 32 is 320. But local scope code did not return to global. -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { +// console.log(a * b); +//} -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..5fe106961 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. -function sum(a, b) { - return; - a + b; -} +//function sum(a, b) { +// return; +// a + b; +//} console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..c2e9d1493 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,23 +2,44 @@ // Predict the output of the following code: // =============> Write your prediction here +// The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth +// because of the variable "num" has been declared. -const num = 103; +//const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +//function getLastDigit() { +// return num.toString().slice(-1); +//} -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +//console.log(`The last digit of 42 is ${getLastDigit(42)}`); +//console.log(`The last digit of 105 is ${getLastDigit(105)}`); +//console.log(`The last digit of 806 is ${getLastDigit(806)}`); + +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem // Now run the code and compare the output to your prediction // =============> write the output here +//The last digit of 42 is 3 +//The last digit of 105 is 3 +//The last digit of 806 is 3 + // Explain why the output is the way it is // =============> write your explanation here +// because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(number) { + return number.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// A: it is because num has been strictly declared as 103 before. and the value is console log could be be applied to function. +// To fix this parameter of getLastDigit should assign for val as a placeholder to allow different value diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..480aeb70c 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + const rawBMI = weight / (height * height); + const result = Math.floor(rawBMI * 10) / 10; + + return result; } + +console.log(calculateBMI(77, 1.83)); diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..7004f2401 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function upperSnakeCase(val) { + const upperCase = val.toUpperCase(); + return upperCase.replace(" ", "_"); +} + +console.log(upperSnakeCase("hello there")); diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..ed39a3a56 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,28 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +function toPounds(penceString) { + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1, + ); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2, + ); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("599p")); +console.log(toPounds("1234p")); +console.log(toPounds("49005p")); +console.log(toPounds("789p")); +console.log(toPounds("85p")); diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..93383d016 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -15,24 +15,26 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); + // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 4 // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here +// =============> 1 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> "01" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 0. The last calling of pad is pad(totalHours). the calculation is 1 (totalMinutues) - 1 (remainingMinutes. The result is 0.) // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 1. pad(remainingSeconds is the last calling foe pad.