diff --git a/Sprint-1/errors/0.js b/Sprint-1/errors/0.js index cf6c5039f..9182c689c 100644 --- a/Sprint-1/errors/0.js +++ b/Sprint-1/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? + + +// by adding comment we can slove this problem \ No newline at end of file diff --git a/Sprint-1/errors/1.js b/Sprint-1/errors/1.js index 7a43cbea7..7eca481d7 100644 --- a/Sprint-1/errors/1.js +++ b/Sprint-1/errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; -age = age + 1; +// const age = 33; +// age = age + 1; + +var age =23; +age =1; \ No newline at end of file diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..debd5204a 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -1,5 +1,12 @@ // 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}`); +/*Answer : The problem is that cityOfBirth is used before it’s defined. + JavaScript runs code from top to bottom, so when console.log tries to use cityOfBirth, it hasn’t been set yet*/ + +// console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +// const myWord= `I was born in ${cityOfBirth}`; +// console.log(myWord); + +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..5c22f6fb7 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,5 +1,5 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,11 @@ 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 + +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); + +/* Prediction +The code won’t work because cardNumber is a number, and .slice() only works on strings and arrays. +To fix this, we need to turn cardNumber into a string first. */ diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..452987393 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime = "20:53"; +const hourClockTime = "08:53"; + +//we can not use number as a variable name ! \ No newline at end of file diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..bf66a9c73 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -4,3 +4,7 @@ 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 + + +//Line 3 increases count by 1. The = sets count to its new value. +console.log(count); \ No newline at end of file diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..dfdb22440 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -7,3 +7,10 @@ const num = 56.5678; // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) // Log your variables to the console to check your answers + +const wholeNumberPart = Math.floor(num); +console.log(wholeNumberPart); +const decimalPart = num -wholeNumberPart; +console.log(decimalPart); +const roundedNum = Math.round(num); +console.log(roundedNum); \ No newline at end of file diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..90fc97d6c 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -4,3 +4,6 @@ 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 = firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0); +console.log(initials); \ No newline at end of file diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index c91cd2ab3..31660aa31 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -12,7 +12,13 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); +const dir = filePath.slice(0, lastSlashIndex); +const dotIndex = base.lastIndexOf("."); +const ext = base.slice(dotIndex); + console.log(`The base part of ${filePath} is ${base}`); +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 292f83aab..fac9ac6f2 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -2,7 +2,7 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - +console.log(num); // 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 // It will help to think about the order in which expressions are evaluated diff --git a/Sprint-1/interpret/percentage-change.js b/Sprint-1/interpret/percentage-change.js index e24ecb8e1..e9de1ac29 100644 --- a/Sprint-1/interpret/percentage-change.js +++ b/Sprint-1/interpret/percentage-change.js @@ -2,12 +2,12 @@ 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 @@ -20,3 +20,29 @@ console.log(`The percentage change is ${percentageChange}`); // 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? + + +/* +a) There are 4 function calls in total: + 1. carPrice.replaceAll(",", "") + 2. priceAfterOneYear.replaceAll(",", "") + 3. Number(...) (used in two places) + +b) The error occurs on the line where priceAfterOneYear is reassigned. + Reason: Missing comma in the replaceAll function call. + Fix: Correct it to priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + +c) Variable reassignment statements: + 1. carPrice = Number(carPrice.replaceAll(",", "")); + 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + +d) Variable declaration statements: + 1. let carPrice = "10,000"; + 2. let priceAfterOneYear = "8,543"; + 3. const priceDifference = carPrice - priceAfterOneYear; + 4. const percentageChange = (priceDifference / carPrice) * 100; + +e) The expression Number(carPrice.replaceAll(",", "")): + - Removes commas from the carPrice string and converts it to a number. + - Purpose: To get a numerical value from the string for calculations. +*/ diff --git a/Sprint-1/interpret/time-format.js b/Sprint-1/interpret/time-format.js index 83232e43a..1f24faad5 100644 --- a/Sprint-1/interpret/time-format.js +++ b/Sprint-1/interpret/time-format.js @@ -22,3 +22,11 @@ console.log(result); // 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 + +// Answers: +// a) There are 5 variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours +// b) There is 1 function call: console.log() +// c) movieLength % 60 finds leftover seconds that don’t fit into a full minute +// d) totalMinutes gives the number of complete minutes by removing extra seconds +// e) result is the formatted time (HH:MM:SS); a better name could be formattedTime +// f) Code works for any non-negative movieLength, but not for negative values \ No newline at end of file diff --git a/Sprint-1/interpret/to-pounds.js b/Sprint-1/interpret/to-pounds.js index 60c9ace69..983314921 100644 --- a/Sprint-1/interpret/to-pounds.js +++ b/Sprint-1/interpret/to-pounds.js @@ -1,21 +1,31 @@ -const penceString = "399p"; +const penceString = "399p"; // Initialize a string variable with the value "399p", which represents 399 pence. -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); +// Remove the trailing 'p' from the string +const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); +// This line uses the substring method to take all characters from the start up to (but not including) the last character 'p'. +// The result will be "399". -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); +// Pad the pence number string to ensure it has at least 3 digits +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// This line ensures that the string has a minimum length of 3 characters, adding leading zeros if necessary. +// For example, "5" would become "005", but "399" stays as "399". +// Extract the pounds part from the padded pence string +const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); +// This line takes all characters except the last two, which represent the pence. +// For "399", it results in "3", meaning 3 pounds. + + // Extract the pence part from the padded pence string const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + .substring(paddedPenceNumberString.length - 2) // Get the last two characters, which represent the pence. + .padEnd(2, "0"); // Ensure that there are always two digits in the pence part, adding a zero if necessary. +// For "399", this gives "99". If it were "5", it would give "05". + +// Print the final formatted price in pounds +console.log(`£${pounds}.${pence}`); +// This line combines pounds and pence into a string formatted as "£3.99". +// It uses template literals to insert the pound and pence values into the string. -console.log(`£${pounds}.${pence}`); // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a8..b60525d41 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,7 +1,19 @@ // Predict and explain first... function multiply(a, b) { + // This function calculates the product of two numbers a and b. + // It logs the result (a * b) to the console but does not return anything. console.log(a * b); } + +// Here, we are calling the multiply function with 10 and 32. +// The function will log the result (320) to the console. console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + + +// However, the multiply function does not return a value. +// So, ${multiply(10, 32)} becomes undefined. +// The final output of this console.log will be: +// 1. First, 320 is printed from the multiply function. +// 2. Then, "The result of multiplying 10 and 32 is undefined" is printed. \ No newline at end of file diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020cae..fce05d662 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,8 +1,15 @@ // Predict and explain first... function sum(a, b) { - return; - a + b; + // The function has a 'return;' statement, which exits the function immediately. + // The line 'a + b' is ignored because it is placed after the 'return;' statement. + return; // The function ends here and returns undefined. + a + b; // This code is unreachable and will not execute. } +// Here, we call the sum function with 10 and 32. +// Since the function returns undefined, the result in the template literal will be undefined. console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// Output: +// "The sum of 10 and 32 is undefined" \ No newline at end of file diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a8..cc2cde271 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,14 +1,59 @@ // Predict and explain first... +// Declare a constant `num` with the value 103 const num = 103; +// Define a function `getLastDigit()` which is intended to return the last digit of a number. function getLastDigit() { + // Convert `num` to a string and use `slice(-1)` to get the last character of the string. + // But `num` is always 103, so this will always return '3' regardless of the argument passed. return num.toString().slice(-1); } +// Log the result of calling `getLastDigit(42)` +// The function doesn't use the argument 42 and will always return '3' (from `num` = 103). console.log(`The last digit of 42 is ${getLastDigit(42)}`); + +// Log the result of calling `getLastDigit(105)` +// The function doesn't use the argument 105 and will always return '3'. console.log(`The last digit of 105 is ${getLastDigit(105)}`); + +// Log the result of calling `getLastDigit(806)` +// The function doesn't use the argument 806 and will always return '3'. 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 + + +// Explanation: +// The original function was using a fixed constant `num` to get the last digit, +// which meant that it always returned the last digit of `103`, no matter +// what number was passed to the function. +// To fix this, we need to update the function to accept a number as an argument +// and use that argument to extract the last digit. + +// Updated Function to Get Last Digit: +function getLastDigit(num) { + // Convert the number to a string and use `slice(-1)` to extract the last digit. + // We now use the `num` passed as an argument to the function. + return num.toString().slice(-1); // This will correctly return the last digit of the number passed. +} + +// Logging the results for different numbers: + +// Call the function with 42 +// The function should return '2' as it's the last digit of 42 +console.log(`The last digit of 42 is ${getLastDigit(42)}`); // Expected Output: 2 + +// Call the function with 105 +// The function should return '5' as it's the last digit of 105 +console.log(`The last digit of 105 is ${getLastDigit(105)}`); // Expected Output: 5 + +// Call the function with 806 +// The function should return '6' as it's the last digit of 806 +console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Expected Output: 6 + + +//NOTE : please comment first code if you want to run my codes .. \ No newline at end of file diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e118..49fb6a91a 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -3,7 +3,17 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +// Function to capitalize the first letter of the string function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + // Problem: We can't redeclare 'str' inside the function as it's already a parameter + // Fix: Instead of redeclaring, we just modify the existing 'str' variable directly. + + // let str = `${str[0].toUpperCase()}${str.slice(1)} // we should remove the Let + + str = `${str[0].toUpperCase()}${str.slice(1)}`; + // Capitalize the first letter and combine with the rest of the string + + return str; // Return the modified string } + +console.log(capitalise("coding")); // Expected Output: "Coding" \ No newline at end of file diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed237..dbb0027bc 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -3,11 +3,16 @@ // Why will an error occur when this program runs? // 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 to convert decimal to percentage +function convertToPercentage(decimalNumber) { + // const decimalNumber = 0.5; + // Removed the redeclaration of decimalNumber and just use the parameter + const percentage = `${decimalNumber * 100}%`; // Convert the decimal to percentage + return percentage; } -console.log(decimalNumber); +// Now we pass a decimal number as an argument to the function +console.log(convertToPercentage(0.5)); // Expected Output: "50%" + diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9e..5782897dd 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -3,8 +3,22 @@ // this function should square any number but instead we're going to get an error -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } +// The original function is incorrect because: +// 1. The function parameter is written as `3`, which is a value, not a valid parameter name. +// 2. Inside the function, the variable `num` is referenced, but it has not been defined anywhere, causing a ReferenceError. + +function square(number) { + // Now, instead of `3`, we have a valid parameter name `number`. + // The function will take `number` as input and return `number * number` (the square of the number). + + return number * number; // Multiply the number by itself to square it. + } + + // Testing the function by passing the value `3` to it + console.log(square(3)); // Expected Output: 9 + \ No newline at end of file diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062d..4373b1fe1 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -1,24 +1,37 @@ // This is the latest solution to the problem from the prep. // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. +//updated code + function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); + const hours = Number(time.slice(0, 2)); // Get the hours as a number from the time string + + if (hours === 12) { + return `${time} pm`; // Special case for 12:00, it's always 12 PM + } + if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:00 pm`; // Convert hours greater than 12 to PM and subtract 12 } - return `${time} am`; + + return `${time} am`; // For hours 12 or less, return as AM } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); +// Test cases +console.assert(formatAs12HourClock("08:00") === "08:00 am", `Test failed for 08:00`); +console.assert(formatAs12HourClock("23:00") === "11:00 pm", `Test failed for 23:00`); +console.assert(formatAs12HourClock("12:00") === "12:00 pm", `Test failed for 12:00`); +console.assert(formatAs12HourClock("00:00") === "00:00 am", `Test failed for 00:00`); + + +// Edge case tests + +// Test for noon (12:00 PM) +console.assert(formatAs12HourClock("12:00") === "12:00 pm", `Test failed for 12:00 pm`); + +// Test for midnight (00:00), should be 00:00 am +console.assert(formatAs12HourClock("00:00") === "00:00 am", `Test failed for 00:00 am`); + +// Test for 1 AM and 1 PM +console.assert(formatAs12HourClock("01:00") === "01:00 am", `Test failed for 01:00 am`); + diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d48..d0e38c456 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -12,4 +12,27 @@ // Given someone's weight in kg and height in metres // Then when we call this function with the weight and height + + // It should return their Body Mass Index to 1 decimal place + +// Function to calculate BMI +function calculateBMI(weight, height) { + // Step 1: Square the height + const heightSquared = height * height; + + // Step 2: Calculate BMI + const bmi = weight / heightSquared; + + // Step 3: Round the BMI to 1 decimal place + const roundedBMI = bmi.toFixed(1); + + // Step 4: Return the BMI value + return parseFloat(roundedBMI); + } + + // Test cases + console.log(calculateBMI(109, 1.81)); // Expected output: 23.4 + console.log(calculateBMI(80, 1.80)); // Expected output: 24.7 + console.log(calculateBMI(55, 1.60)); // Expected output: 21.5 + diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b6..d3974b44f 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,24 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + +// Function to convert string to UPPER_SNAKE_CASE +function toUpperSnakeCase(inputString) { + // Step 1: Split the string by spaces into an array of words + const wordsArray = inputString.split(' '); + + // Step 2: Convert each word to uppercase + const upperCaseWords = wordsArray.map(word => word.toUpperCase()); + + // Step 3: Join the array of words with underscores + const result = upperCaseWords.join('_'); + + // Step 4: Return the result + return result; + } + + // Test cases + console.log(toUpperSnakeCase("hello there")); // Expected output: "HELLO_THERE" + console.log(toUpperSnakeCase("lord of the rings")); // Expected output: "LORD_OF_THE_RINGS" + console.log(toUpperSnakeCase("java script is awesome")); // Expected output: "JAVA_SCRIPT_IS_AWESOME" + \ No newline at end of file diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 6265a1a70..bc57d50e5 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,20 @@ // 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 to convert kilograms to pounds +function toPounds(kg) { + // 1 kg = 2.20462 pounds + const pounds = kg * 2.20462; + + // Return the result + return pounds; + } + + // Test cases + console.log(toPounds(1)); // Expected output: 2.20462 + console.log(toPounds(5)); // Expected output: 11.0231 + console.log(toPounds(100)); // Expected output: 220.462 + console.log(toPounds(0.5)); // Expected output: 1.10231 + console.log(toPounds(75)); // Expected output: 165.3465 + \ No newline at end of file diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb167226..ae1778853 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,17 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + +// Function to calculate price with VAT added +function addVAT(price) { + const vatInclusivePrice = price * 1.2; // Multiply by 1.2 to add 20% VAT + return vatInclusivePrice; // Return the new price with VAT + } + + // Test cases + console.log(addVAT(50)); // Expected output: 60 (50 + 20% VAT) + console.log(addVAT(100)); // Expected output: 120 (100 + 20% VAT) + console.log(addVAT(25)); // Expected output: 30 (25 + 20% VAT) + console.log(addVAT(75)); // Expected output: 90 (75 + 20% VAT) + console.log(addVAT(10)); // Expected output: 12 (10 + 20% VAT) + \ No newline at end of file diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c1619..c7dfad5fa 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -29,3 +29,15 @@ function formatTimeDisplay(seconds) { // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + +/* ANSWERS + +(a) The function pad is called 3 times when you use formatTimeDisplay with 61 seconds. + +(b) The value of num when pad is called for the first time is 0. + +(c) The value returned by pad when it is called for the first time is "00". + +(d) The value of num when pad is called for the last time is 1. + +(e) The value returned by pad when it is called for the last time is "01". */ \ No newline at end of file