From 74f8a78f5a559105ce27b30689ee1a12778d1ba2 Mon Sep 17 00:00:00 2001 From: DinicaCB Date: Mon, 22 Dec 2025 13:07:09 +0100 Subject: [PATCH 1/4] answer 0.js --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..65ad3030d 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -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? \ No newline at end of file From f979b3d7861e21677f2d0034450e9fb3b8ee9b81 Mon Sep 17 00:00:00 2001 From: DinicaCB Date: Mon, 22 Dec 2025 14:10:09 +0100 Subject: [PATCH 2/4] all the answer --- Sprint-1/2-mandatory-errors/1.js | 3 ++- Sprint-1/2-mandatory-errors/2.js | 4 +++- Sprint-1/2-mandatory-errors/3.js | 8 ++++++- Sprint-1/2-mandatory-errors/4.js | 9 ++++++-- .../1-percentage-change.js | 20 ++++++++++++++++- .../3-mandatory-interpret/2-time-format.js | 22 +++++++++++++++++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 19 +++++++++++++++- 7 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..d660966b7 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 +// I changed for let -const age = 33; +let age = 33; age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..6d4dc4ae3 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 ? +// I have ti change the order -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..e95738ad1 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +/*const cardNumber = 4533787178994213; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +7,9 @@ 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 +/*Answer> The code will not works because slice is strigs and array and +cardNumber is number */ +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.slice(-4); + + diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..2ce09132e 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +/*const 12HourClockTime = "20:53"; +const 24hourClockTime = "08:53"; +*/ + +//Answer: +const Hour12ClockTime = "20:53"; +const hour24ClockTime = "08:53"; \ 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..bdae7723d 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -1,4 +1,4 @@ -let carPrice = "10,000"; +/*let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); @@ -12,11 +12,29 @@ 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 +/* carPrice.replaceAll(",", "") línea 4 +Number(carPrice.replaceAll(",", "")) línea 4 +priceAfterOneYear.replaceAll("," "") línea 5 +Number(priceAfterOneYear.replaceAll("," "")) línea 5 +console.log(...) línea 9 +Total> 5 calls // 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? +is missing coma +console.log(...) in line 9 + // c) Identify all the lines that are variable reassignment statements +carPrice = Number(carPrice.replaceAll(",", "")); in line 4 +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); in line 5 // d) Identify all the lines that are variable declarations +let carPrice = "10,000"; línea 1 +let priceAfterOneYear = "8,543"; línea 2 +const priceDifference = carPrice - priceAfterOneYear; línea 6 +const percentageChange = (priceDifference / carPrice) * 100; línea 7 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +become a price that is string with comas fixed ready to run and show the % +*/ diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..c58262195 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -11,15 +11,37 @@ 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 variables +movieLength +remainingSeconds +totalMinutes +remainingMinutes +totalHours +result // b) How many function calls are there? +1 call +console.log(result) // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +% is the modulo operator. +It returns the remainder of dividing movieLength by 60. +In this case: it calculates how many seconds are left over after counting the full minutes. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +First, subtract the remaining seconds to get only the whole seconds in minutes. Then, divide by 60 to convert seconds to whole minutes. + // e) What do you think the variable result represents? Can you think of a better name for this variable? +The result contains a string in the format: hours:minutes:seconds +movieDurationString + + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +It works for positive numbers of seconds. */ diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..010dcad89 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399p"; +/*const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -25,3 +25,20 @@ 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(0, penceString.length - 1); +Use .substring(start, end) to remove the last character (p) from the string. +penceString.length - 1 index of the last character excluding p +3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +Use .padStart(targetLength, "0") to ensure the chain has at least 3 +4. `const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);` + +`Extracts the digits from the pounds.` `paddedPenceNumberString.length - 2` → leaves the last two digits for the pence.` +5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); + +.substring(start) takes the last two characters, which represent the penny + +.padEnd(2, "0") ensures there are always two digits, padding with 0 if necessary +6. console.log(£${pounds}.${pence}); + +Builds a string in the standard price format: £pounds.pence + From 8d7218ee9868b4edba33a681569240914adbbfed Mon Sep 17 00:00:00 2001 From: DinicaCB Date: Mon, 22 Dec 2025 16:54:43 +0100 Subject: [PATCH 3/4] all answer for Sprint-2 --- Sprint-2/2-mandatory-debug/0.js | 12 ++++++++-- Sprint-2/2-mandatory-debug/1.js | 18 ++++++++++++--- Sprint-2/2-mandatory-debug/2.js | 19 +++++++++++++++- Sprint-2/3-mandatory-implement/1-bmi.js | 8 ++++--- Sprint-2/3-mandatory-implement/2-cases.js | 10 +++++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 22 +++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 16 +++++++++++++- 7 files changed, 95 insertions(+), 10 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..04e77f486 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> not return value so is undefined function multiply(a, b) { console.log(a * b); @@ -8,7 +8,15 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +/* =============> Problem: The function is printing the result, but not returning it. +In template strings, you need the function to return a value (return) for it to appear there. // 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..b2b422056 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,7 @@ -// Predict and explain first... +/* Predict and explain first... // =============> write your prediction here +The `sum` function has a `return` statement on one line and then `a + b` on another. +In JavaScript, if you put `return` alone, without a value, on the same line, the function returns `undefined`.*/ function sum(a, b) { return; @@ -8,6 +10,16 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +/* =============> + The return statement terminates the function's execution on that line. +The expression a + b is never executed. + // 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..985bd2e4c 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -14,11 +14,28 @@ 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 +// =============> write the output here +// La función getLastDigit no toma ningún parámetro y always usa la variable global num que es 103. + // Explain why the output is the way it is // =============> write your explanation here + +// getLastDigit no recibe un número como argumento, así que ignora los valores que se pasan en los console.log. + // 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 + +/* getLastDigit wasn't using the parameter because it had no defined parameters. +The correct function should take a number and return its last digit using .toString().slice(-1). diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..265bc71be 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,8 @@ // Then when we call this function with the weight and height // 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 + +/function calculateBMI(weight, height) { + const bmi = weight / (height * height); // calcular el BMI + return bmi.toFixed(1); // redondear a 1 decimal y devolverlo como string +} diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..4c4aae2e2 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,13 @@ // 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 + +/* Answer*/ +function toUpperSnakeCase(str) { + return str.toUpperCase().replaceAll(" ", "_"); +} +/* str.toUpperCase() converts all text to uppercase +.replaceAll(" ", "_") replaces all spaces with underscores +return returns the transformed string */ + + diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..241dcadd6 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,25 @@ // 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 + + +/* ANSWER */ + +function toPounds(penceString) { + // Quitar la letra "p" al final + const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); + + // AsegurarMe de que la cadena tenga al menos 3 dígitos + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + // Extraer los dígitos de las libras + const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + + // Extraer los dígitos de los pence + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + // Devolver el resultado como string formateado + return `£${pounds}.${pence}`; +} diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..0f31cb1f8 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,38 @@ function formatTimeDisplay(seconds) { 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 +/* 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 +3 times +pad(totalHours) +pad(remainingMinutes) +pad(remainingSeconds) // Call formatTimeDisplay with an input of 61, now answer the following: +0 +seconds = 61 +remainingSeconds = 61 % 60 = 1 +totalMinutes = (61 - 1)/60 = 60/60 = 1 +remainingMinutes = 1 % 60 = 1 +totalHours = (1 - 1)/60 = 0/60 = 0 // 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 +1 // 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 +// 01 */ From e2aeb2cf0bc713b9db80e2d11e03315f131c1e7e Mon Sep 17 00:00:00 2001 From: DinicaCB Date: Mon, 22 Dec 2025 17:00:33 +0100 Subject: [PATCH 4/4] correccion --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 0f31cb1f8..2bcc09cd9 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -26,7 +26,7 @@ pad(remainingSeconds) // Call formatTimeDisplay with an input of 61, now answer the following: 0 seconds = 61 -remainingSeconds = 61 % 60 = 1 +remainingSeconds = 61 % 60 = 0 totalMinutes = (61 - 1)/60 = 60/60 = 1 remainingMinutes = 1 % 60 = 1 totalHours = (1 - 1)/60 = 0/60 = 0