diff --git a/.gitignore b/.gitignore index bde36e530..843c14f21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +**/.DS_Store +package-lock.json \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..8528dad15 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,6 +1,12 @@ let count = 0; - +/* Incrementing by 1 the count value. */ +count = count + 1; +/* Check if count === 1. */ +console.log(count); +/* Incrementing by 1 the count value. */ count = count + 1; +/* Check if count === 2. */ +console.log(count); // 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 diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..7c37fc92d 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -4,8 +4,10 @@ let 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. - -let initials = ``; +/* So many ways to get the first char of a string ! */ +let initials = `${firstName.charAt(0)}${middleName[0]}${lastName.slice(0, 1)}`; +/* Check if ok */ +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..4167dfd2f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -14,10 +14,15 @@ const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); 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 +// Create a variable to store the directories part of the filePath variable. +// Create a variable to store the extension part of the variable. -const dir = ; -const ext = ; +/* Funny ! */ +const dir = filePath.slice(0, lastSlashIndex + 1); +const lastPointIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastPointIndex + 1); +/* Check */ +console.log("The directories part of the filePath is : " + dir); +console.log("The extension part of the variable is : " + ext); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..8f393e825 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,7 +1,37 @@ const minimum = 1; const maximum = 100; +/* + * Well-known JavaScript pattern for generating random integers + * in a specific range [minimum, maximum] (both inclusive). + * minimum <= num <= maximum. + */ +/* Shift along the range from min to max. */ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +/* Check */ +let counter = 0; +const min = 5; +const max = 20; + +while (counter <= 5) { + console.log("\nMinimum", min, "Maximum", max); + // Mystery of Mathematics. + const m = max - min + 1; + console.log("(max - min + 1) => ", m); + /* return random float in between 0 and 1 (non inclusive) */ + const rd = Math.random(); + console.log("random", rd); + // Mystery of Mathematics. + console.log(`(${m} * random) => `, m * rd); + /* Math.floor return the nearest lower integer + * E.g. Math.floor(3.9) === 3; + * Return a range 0 => 99. + */ + const int = Math.floor(rd * m); + console.log(`Math.floor(${m} * random) =>`, int); + console.log(`${int} + ${min} =>`, Math.floor(rd * m) + min); + counter++; +} // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..7f6de0f21 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -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? */ +/* + * Just comment it. +*/ \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..4664a87d8 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 - -const age = 33; +/* TypeError: Assignment to constant variable. */ +// const age = 33; +let age = 33; age = age + 1; +/* Check if ok. */ +console.log(age); diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..c5ffaab65 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,7 @@ // 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}`); +/* Cannot access 'cityOfBirth' before initialization */ +// const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..bfc078a47 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,16 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +/* cardNumber is a number but slice() is a String method. */ +/* TypeError: cardNumber.slice is not a function. */ +//const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +/* Another way to cast a number (string + number == string) */ +const otherLast4Digits = `${cardNumber}`.toString().slice(-4); +const anotherLast4Digits = ("" + cardNumber).slice(-4); +/* Check if ok */ +console.log(last4Digits); +console.log(otherLast4Digits); +console.log(anotherLast4Digits); + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..a183e3d7f 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,9 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +/* Js variables are not allowed to start with digit */ +/* SyntaxError: Invalid or unexpected token */ +// const 12HourClockTime = "20:53"; +// const 24hourClockTime = "08:53"; +const hourClockTime12 = "20:53"; +const hourClockTime24 = "08:53"; +/* Check if ok. */ +console.log("hourClockTime12 : " + hourClockTime12); +console.log("hourClockTime24 : " + hourClockTime24); \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..9ff524be8 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,21 +2,42 @@ 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; -console.log(`The percentage change is ${percentageChange}`); +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) How many function calls are there in this file? +// Write down all the lines where a function call is made. +/* + * line 4 & 5 => replaceAll() - String method. + * line 4 & 5 => Number() - built-in constructor function + * line 10 => console.log() - built-in constructor function +*/ -// 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? +// 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? +/* + * line 5 => Miss a comma in arguments declaration. +*/ // c) Identify all the lines that are variable reassignment statements +/* + * lines 4 & 5 => carPrice & priceAfterOneYear are reassigned. +*/ // d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +/* + * lines 1 & 2 => carPrice & priceAfterOneYear. + * lines 7 & 8 => priceDifference & percentageChange. +*/ + +// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing +// what is the purpose of this expression? +/* + * Cast a string to Number. +*/ diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..8a49dd562 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = -8784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,40 @@ 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? +/* + * 6 variable's declarations: + * movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result. +*/ // b) How many function calls are there? +/* + * Only console.log() +*/ // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +/* + * Modulo (%) is use to return the rest number of a division. + * 8784 % 60 = 8784 - (60 × Math.floor(8784 / 60)); +*/ +console.log( "\nModule explained"); +console.log("8784 % 60 =" ,8784 - (60 * Math.floor(8784 / 60))); -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -// e) What do you think the variable result represents? Can you think of a better name for this variable? -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// d) Interpret line 4, what does the expression assigned to totalMinutes mean? +/* + * The rest number are the seconds. + * We substract them to the time length then timelength / 60 result + * is minutes (60 seconds in a minute). +*/ + +// e) What do you think the variable result represents? +// Can you think of a better name for this variable? + /* getClockTime() */ + +// f) Try experimenting with different values of movieLength. +// Will this code work for all values of movieLength? Explain your answer +/* + * Yes but the result display is not optimal in case + * movieLength = 0 ormovieLength < 0 or totalHours === 0 or some of the value < 10. +*/ diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..93a000874 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -10,6 +10,8 @@ const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +console.log(paddedPenceNumberString.charAt(0)); + const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) @@ -25,3 +27,34 @@ 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 = penceString.substring( penceString.length - 1); + * Assign the penceStringWithoutTrailingP variable to string penceString trailing last char of it. + * length of penceString - 1 because index begins to 0 + * String method substring() parameter does not accept negative index (unlike slice) + * String method substring() returns charAt(3) to the end. + * penceString is not muted (remains the same). + * + * 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + * penceStringWithoutTrailingP.padStart(3, "0") = add (number - string.length) "0" + * Here penceStringWithoutTrailingP.length = 3 so 3 - 3 = nothing to add. + * useful to add 0 if the price < 1 pound (Impossible nowadays). + + * 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); + * String method substring() returns charAt(0) to charAt(1)(3- 1) non inclusif, + * Equivalent to substring( 0, 1); + * Equivalent to paddedPenceNumberString.charAt(0); + + * 5. const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + * String method substring() returns the 2 last char of the string. + * Here the pences. + * padEnd(2, "0") same system than above but add "0" at the end if the string.length < 2 + * E.g. "9" => "90". + + * 6. console.log(`£${pounds}.${pence}`); + * Display in the console currency + pound's value + separator + pence's value + * thanks to the template literals ``. + +*/ diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..8c01bf619 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -14,3 +14,7 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +- console.log(["message"], value.toString()) +- console.assert(assertion, "message", [optionalParams]); +- - assertion returns a boolean (false / true). If false the message will be displayed in the console. +- - E.g. console.assert(5 < 2, "You are really dumb into mathematics"); diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..0172dcf8c 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,16 @@ // Predict and explain first... -// =============> write your prediction here +// Guess init a variable with the same name than the argument is not a good idea. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; -} +} */ -// =============> write your explanation here -// =============> write your new code here +// SyntaxError: Identifier 'str' has already been declared + function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} +console.log(capitalise("hello world")); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..21f5fad55 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,27 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// Variable 'decimalNumber' is already declared. And this declaration is no needed. +// console.log(decimalNumber); will throw an error. const is block scoped. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +/* function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(decimalNumber); */ -// =============> write your explanation here +// SyntaxError: Identifier 'decimalNumber' has already been declared // Finally, correct the code to fix the problem -// =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); + diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..9c1401df6 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,23 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// '3' is a number not an argument. -function square(3) { +/* function square(3) { return num * num; -} +} */ -// =============> write the error message here +// SyntaxError: Unexpected number -// =============> explain this error message here +// '3' is a number not an argument. +// An argument is a variable and must not begin with a number. +// the var 'num' is coming from nowhere. // 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-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..56763df67 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,17 @@ // Predict and explain first... -// =============> write your prediction here +// The result of multiplying 10 and 32 is undefined -function multiply(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 +// No return in the function // 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-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..017f2ba34 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,17 @@ // Predict and explain first... -// =============> write your prediction here +// The sum of 10 and 32 is undefined -function sum(a, b) { +/* function sum(a, b) { return; a + b; } -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); */ -// =============> write your explanation here +// return nothing. // 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-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..b9527877b 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,28 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// No argument passed in the function. +// the number value is always 103; -const num = 103; +/* + const num = 103; -function getLastDigit() { + 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)}`); +*/ + +// Now run the code and compare the output to your prediction +// The last digit of 806 is 3 +// Explain why the output is the way it is +// the num value is always 103 (const num = 103) +// Finally, correct the code to fix the problem + +function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,12 +30,5 @@ 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)}`); -// Now run the code and compare the output to your prediction -// =============> write the output here -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..f4abae0e9 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + // return the BMI of someone based off their weight and height. + return (weight / (height * height)).toFixed(1); +} + +console.log(`Bob's Body Mass Index is ${calculateBMI(120, 1.6)}`); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..4de600bf2 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 getUpperSnakeCase(str) { + return str.toUpperCase().trim().replace(/\s/g, "_"); +} +const str = " once upon a time "; +console.log(`'${str}' in UPPER_SNAKE_CASE is '${getUpperSnakeCase(str)}'.`); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..1e7c6a243 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,19 @@ // 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 toPound(pences){ + + const penceWithoutTrailingP = pences.substring( 0,pences.length - 1); + const paddedPenceNumberStr = penceWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberStr.substring( 0, paddedPenceNumberStr.length - 2 ); + const pence = paddedPenceNumberStr + .substring(paddedPenceNumberStr.length - 2) + .padEnd(2, "0"); + + return `£${pounds}.${pence}`; +} +const pences = ["399p", "1600p", "50p", "200p"]; + for (p of pences){ + console.log(`${p} is ${toPound(p)}`); + } \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..492dfa0d5 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -1,5 +1,6 @@ function pad(num) { - return num.toString().padStart(2, "0"); + const result = num.toString().padStart(2, "0"); + return result; } function formatTimeDisplay(seconds) { @@ -7,28 +8,29 @@ function formatTimeDisplay(seconds) { const totalMinutes = (seconds - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; + console.log("remainingSeconds",remainingSeconds); return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } - -// 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 +console.log("formatTimeDisplay(61)", formatTimeDisplay(61)); // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// 3 times. // 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 +// 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// "00" -// 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 +// d) What is the value assigned to num when pad is called for the last time in this program? +// Explain your answer +// Remaining seconds => 1 (61 seconds) -// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// e) What is the return value assigned to num when pad is called for the last time in this program? +// Explain your answer +// "01" => pad fill the string < 2 with 0.