From af8a542451c6cb862f28224ae60c1987ed045b26 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 18 Oct 2025 10:26:02 +0100 Subject: [PATCH 01/29] Answering the first task of sprint 1 --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..3e80e5060 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ 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 returns the value of count after adding 1 to it and assigns this new value back to count \ No newline at end of file From e4c2e5759b3fb7d64058708f0095fe81bf5195c6 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 18 Oct 2025 22:36:03 +0100 Subject: [PATCH 02/29] creating the dir and ext variables --- Sprint-1/1-key-exercises/2-initials.js | 4 +++- Sprint-1/1-key-exercises/3-paths.js | 22 ++++++++++------------ number-game-errors.html | 0 3 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 number-game-errors.html diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..df2f3a93d 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -2,10 +2,12 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; +let initials = + // 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 = ``; +let initials = `${firstName[C]}${middleName[K]}${lastName[J]}`; // 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..dd6b9c839 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -1,5 +1,3 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - // ┌─────────────────────┬────────────┐ // │ dir │ base │ // ├──────┬ ├──────┬─────┤ @@ -7,17 +5,17 @@ // " / home/user/dir / file .txt " // └──────┴──────────────┴──────┴─────┘ -// (All spaces in the "" line should be ignored. They are purely for formatting.) - const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -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 +// Find the index of the last slash and the last dot +const lastSlashIndex = filePath.lastIndexOf("/"); +const lastDotIndex = filePath.lastIndexOf("."); -const dir = ; -const ext = ; +// Extract each part +const base = filePath.slice(lastSlashIndex + 1); // "file.txt" +const dir = filePath.slice(0, lastSlashIndex); // "/Users/mitch/cyf/Module-JS1/week-1/interpret" +const ext = filePath.slice(lastDotIndex + 1); // "txt" -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The base part of ${filePath} is ${base}`); +console.log(`The ext part of ${filePath} is ${ext}`); diff --git a/number-game-errors.html b/number-game-errors.html new file mode 100644 index 000000000..e69de29bb From b21591e99e826bb6b276d3e77889db980a1f2db2 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 18 Oct 2025 23:25:32 +0100 Subject: [PATCH 03/29] creating a variable --- Sprint-1/1-key-exercises/2-initials.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index df2f3a93d..3a5a0205b 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -2,12 +2,13 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; -let initials = + // 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[C]}${middleName[K]}${lastName[J]}`; +let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From 4102ecbf9322cb3d71a8c7e528ea3550858c45e6 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:07:17 +0100 Subject: [PATCH 04/29] Updating the answer --- Sprint-1/1-key-exercises/3-paths.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index dd6b9c839..80cc0a561 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -5,17 +5,20 @@ // " / home/user/dir / file .txt " // └──────┴──────────────┴──────┴─────┘ -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -// Find the index of the last slash and the last dot + +// all spaces in the "" line should be ignored. THey are purely for formatting. + +const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); -const lastDotIndex = 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. -// Extract each part -const base = filePath.slice(lastSlashIndex + 1); // "file.txt" -const dir = filePath.slice(0, lastSlashIndex); // "/Users/mitch/cyf/Module-JS1/week-1/interpret" -const ext = filePath.slice(lastDotIndex + 1); // "txt" +const dir = filePath.slice(lastSlashIndex+1) +const ext = filePath.slice(lastDotIndexOf(".") +1); -console.log(`The dir part of ${filePath} is ${dir}`); -console.log(`The base part of ${filePath} is ${base}`); -console.log(`The ext part of ${filePath} is ${ext}`); +console.log (dir) +// https://www.google.com/search?q=slice+mdn \ No newline at end of file From 8f90b4f044276eb444b9b3de3e50441396fc0323 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:10:49 +0100 Subject: [PATCH 05/29] Modifying the answer --- Sprint-1/1-key-exercises/2-initials.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 3a5a0205b..5ea5c674f 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -7,8 +7,9 @@ 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); +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; + +console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn From 1da375f69baa6907102cd7a783163304bde5f399 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:24:47 +0100 Subject: [PATCH 06/29] Answering th task 1.js --- Sprint-1/2-mandatory-errors/1.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..5ab34c492 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; +// in this case, we will need to replace the const keyword with let keyword as const vasriable refuses to be reassigned. +let age = 33; age = age + 1; + +console.log(age); \ No newline at end of file From beda7c459ffa652283cceed96d87a2f3b5ca81b0 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:27:11 +0100 Subject: [PATCH 07/29] Answering th task 1.js --- Sprint-1/1-key-exercises/1-count.js | 2 +- Sprint-1/1-key-exercises/4-random.js | 15 +++++++++++++++ Sprint-1/2-mandatory-errors/0.js | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 3e80e5060..b6b3bb43f 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,4 @@ 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 returns the value of count after adding 1 to it and assigns this new value back to count \ No newline at end of file +// line 3 returns the incurmented value of count after adding 1 to it and assigns this new value back to count \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..7da6c30bc 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,18 @@ 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); \ No newline at end of file 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 e7f48d3b6e37e6148c15558ba859867450d34e68 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:31:49 +0100 Subject: [PATCH 08/29] Answering 2.js --- Sprint-1/2-mandatory-errors/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..dcc8ce5a4 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // 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}`); +// we need to declare the variable cityOfBirth first then we can print it out. const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file From a66131089337aef8035649c65fdfe14b3c3ed8c5 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Thu, 23 Oct 2025 23:50:47 +0100 Subject: [PATCH 09/29] Answering 3.js --- Sprint-1/2-mandatory-errors/3.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..5e0a141ce 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ 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 +8,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 + +// it seems that the code is not working because the cardNumber variable is not defined as a string. +// my prediction is true. + +//we need to add string to the variable cardNumber variable before using the slice method then to print the code out. \ No newline at end of file From f4e13bc29885fce250784f8e9bdb996c5f97486a Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 24 Oct 2025 00:47:42 +0100 Subject: [PATCH 10/29] Solving the code issue --- Sprint-1/2-mandatory-errors/4.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..d53812c4e 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,16 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; + +// we have to convert the identifiers of the variables to valid ones by removing the 12 and 24 digits and to put them in camel case format. +const twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; + +console.log(twelveHourClockTime); +console.log(twentyFourHourClockTime); + +// The twelveHourClockTime and twentyFourHourClockTime variables should store the respective time formats +// However, the code isn't working +// Before running the code, make and explain a prediction about why the code won't work +// 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 variable names to valid identifiers in order to get the correct value From b6b4ffcad494cc118f17da181da6e239997633cb Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 24 Oct 2025 01:12:21 +0100 Subject: [PATCH 11/29] Answering the questions --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..5d5230561 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,11 +12,12 @@ 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 - +// five fuction calls, in line 4, number(), and replaceAll(). in line 5, number() and replaceAll(), in line 8, console.log(). // 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? - +//in line 5, a syntax error because of the missing comma inside the replaceAll method parentheses. we can fix this problem by adding the missing comma. // c) Identify all the lines that are variable reassignment statements - +// in line 4 carPrice variable is reassigned and in line 5 priceAfterONeYear as well. // d) Identify all the lines that are variable declarations - +// four variable declarations in line 1 carPrice variable is declared, in line 2 priceAfterOneYear variable is declared, in line 7 priceDifference variable is declared, and in line 8 percentageChange variable is declared. // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// the purpose of this expression number(carPrice.replaceAll(",","")) is to change a string value that contains commas into a number value by removing the commas first using the replaceAll method and then converting the resulting string into a number using the Number function. \ No newline at end of file From 2478f223d1ab29b0c6ec3fc9794fc7addae134fa Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 24 Oct 2025 01:23:12 +0100 Subject: [PATCH 12/29] answering the task questions --- Sprint-1/3-mandatory-interpret/2-time-format.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..fc2343cc4 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,15 @@ 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? - +// six variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result. // b) How many function calls are there? - +// only one fuction call: console.log() in line 10. // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - +// the expression movieLength % 60 is using the modulus operator (%) to find the remainder when movieLength is divided by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +// the expression assigned to totalMinutes is calculating the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in seconds and then dividing the result by 60 to convert it to minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? - +// the variable result represents the formatted string of the movie length in hours, minutes, and seconds. a better name for this variable could be formattedMovieLength or movieDurationFormatted. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// yes, this code will work for all values of movieLength as long as it is a non-negative integer representing the length of the movie in seconds. the code correctly calculates the hours, minutes, and seconds for any given length of time in seconds. \ No newline at end of file From 8beb07d1534eb7e3ccd276cff83ab6d1fc352a88 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 25 Oct 2025 23:57:32 +0100 Subject: [PATCH 13/29] Answering 3-to-pounds.js --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..a400cdfc1 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,13 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// to begin we can start with +//1- const penceSring= "399p": initialises a string variable with the value "399p" +//2- const penceStringWithoutTrailingP= a string value "399" is reassigned to penceStringWithoutTrailingP by removing the last character "p" from penceString using the substring method +//3- const paddedPenceNumberString= declared new variable, padStart ensure any argument passed is at least 3 characters long by adding leading zeros if necessary +//4- line 9 a new variable pence is declared and its value comes from the padded string by removing the last two characters which represent the pence. +//5- line 14 const pence= declared variable and the variable is the result after extracting the last two characters from paddedPenceNumberString using substring method and padEnd method is used to ensure that the pence value is always two digits long by adding trailing zeros if necessary +// from the pence string and pads it to two characters to have two digits number. +//6- line 18: console.log (`£${pounds}.${pence}`): returns money amount combing pounds and pence along with the £ symbol +//eg. £3.99 \ No newline at end of file From f070a007dd24320f5cf1a7abc683ff6493463f93 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 00:25:54 +0000 Subject: [PATCH 14/29] Answering the task --- Sprint-2/1-key-errors/0.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..9fbe83452 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,23 @@ // Predict and explain first... -// =============> write your prediction here +// =============> I predict that we will not need to write let in line 8 as str is already declared +// as an argument within the function captialise. // 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; +// } + +// capitalise ('hello'); +//==============> A syntaxError occurred as 'str' is being cleared. + + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +console.log (capitalise ('hello')); + -// =============> write your explanation here -// =============> write your new code here From ad0f006e052c74b97e23fd1eaecd6d6e7f7011bb Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 00:47:43 +0000 Subject: [PATCH 15/29] Answering the task --- Sprint-2/1-key-errors/1.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..b7e9c83b8 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,32 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> I believe that the function converToPercentage is not mentioned in the console.log statement. +// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. // 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 +// =============> A syntaxError occurred saying decimalNumber is already declared. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage() { + const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage()); + +// the new code runs without error and outputs "50%" From e082897ab0db18a722a49f4c20a2b3779a970c8e Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 00:52:08 +0000 Subject: [PATCH 16/29] fixing the error to add a comment slashes --- Sprint-2/1-key-errors/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index b7e9c83b8..44f4fa8ff 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> I believe that the function converToPercentage is not mentioned in the console.log statement. +// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement. // Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. // Try playing computer with the example to work out what is going on @@ -11,7 +11,7 @@ // const percentage = `${decimalNumber * 100}%`; // return percentage; -} +//} // console.log(decimalNumber); From 85bcc9bc5cdc4c365aa3f0b0a186cc8231140a93 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 01:13:24 +0000 Subject: [PATCH 17/29] Answering the task --- Sprint-2/1-key-errors/2.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..3438e406c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,25 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> The num parameter should be mentioned inside the function square instead of the number 3. +// then it should be called as square (3) in the console.log statement. -function square(3) { - return num * num; -} +//function square(3) { +//return num * num; +//} + +// =============> function square(3) syntaxError: Unexpected number. +// =============> 3 wasn't expected... instead a declaration like 'num' was expected. -// =============> write the error message here -// =============> explain this error message here // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +console.log(square(3)); From 491f9b8484d9b5a9067a91d1c44738fce534c914 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 23:07:05 +0000 Subject: [PATCH 18/29] Answering the task --- Sprint-2/2-mandatory-debug/0.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..9acb66bbf 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,20 @@ // Predict and explain first... -// =============> write your prediction here +// =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better +//because the console.log would only print a*b. -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 +// =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined' +// as the multiply parameters weren't considered as parameters inside the function multiply. // 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)}`); \ No newline at end of file From c5a8edb76226138bb6e9868833df3f34e0f13993 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 23:38:09 +0000 Subject: [PATCH 19/29] Answering the task --- Sprint-2/2-mandatory-debug/1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..626b920e7 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,13 @@ // Predict and explain first... -// =============> write your prediction here +// =============> SyntaxError will occur due to putting a semicolon after return. function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'. // Finally, correct the code to fix the problem // =============> write your new code here +// we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return. \ No newline at end of file From b0547d6889a4c1b8078346a643ea7a374a2a026e Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Fri, 31 Oct 2025 23:55:32 +0000 Subject: [PATCH 20/29] Answering the task --- Sprint-2/2-mandatory-debug/2.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..7c2a6f004 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,34 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> The code will return 3 as a string first, but after calling the getLastDigit function, +// it will not return anything because every number based will be converted to string. -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)}`); // 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 +// =============> The last digit of 42 is 3 three times. +// the prediction was close but not accurate, the case is that the parameter num needs to be +//the function instead of const num = 103. +// =============> // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + 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)}`); // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// parameter num needs to be with the getLastDigit function instead of const num=103. From 9b194a5c3415847442d3c9421a3ffc296959426b Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 00:05:22 +0000 Subject: [PATCH 21/29] Answering the task --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..9c9ef7a4a 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) { + const bmi = weight / (weight*height); + return bmi.toFixed(1); // return the BMI of someone based off their weight and height -} \ No newline at end of file +} +console.log("the BMI is", calculateBMI(70, 1.73)); \ No newline at end of file From 75b0d3250019a54fc8bdb13d9f0f43ce871bb0a4 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 00:28:03 +0000 Subject: [PATCH 22/29] Change to upper snake case --- Sprint-2/3-mandatory-implement/2-cases.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..60c2682ce 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,15 @@ // 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 capSnakeCase(str) { + const upper = str.toUpperCase(); + const snake = upper.replace(/ /g, "_"); + return snake; +} +console.log(capSnakeCase("lord of the rings")); + +// step 1: get a string input +//step 2: change the upper case +//step 3: replace spaces with underscores +// step 4: return capSnakeCase \ No newline at end of file From 6b1aed0d1b7bf77c2b579fc50c9c6b2f9fa23a1b Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 01:07:36 +0000 Subject: [PATCH 23/29] Answering the task --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..f340ad1e0 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,15 @@ // 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("399p")) +console.log(toPounds("5p")) +console.log(toPounds("5678p")) From 883efa222bbd869b689701259cf18f57dab33f9b Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 01:19:00 +0000 Subject: [PATCH 24/29] Answering the task --- Sprint-2/4-mandatory-interpret/time-format.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..5a6489af9 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,25 +10,25 @@ 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 +// =============> It will be called 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 +// =============> The leftover second is assigned to num as remainingSEconds 61%60 // 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 the remainingSeconds from passed from pad to num is changed to string and padded as 01 From 4ca75b94c92efcce1f085ff3a2de322a1f7c49b4 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 01:58:48 +0000 Subject: [PATCH 25/29] Answering the task --- Sprint-2/5-stretch-extend/format-time.js | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..90c475a37 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,58 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "12:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("12:00"); +const targetOutput4 = "12:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("13:00"); +const targetOutput5 = "1:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); + +const currentOutput7 = formatAs12HourClock("25:00"); +const targetOutput7 = "01:00 am"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}` +); + +// modified code: + +function formatAs12HourClock(time) { + let hours = Number(time.slice(0, 2)); + const minutes = time.slice(3); + + let suffix; + if (hours >= 12) { + suffix = "pm"; + + } else { + suffix = "am"; + } + hours = hours % 12 || 12; // Convert 0 to 12, 13 to 1 + const formattedHours = hours.toString().padStart(2, '0'); + + return `${formattedHours}:${minutes} ${suffix}`; +} + +const currentOutput6 = formatAs12HourClock("23:00"); +const targetOutput6 = "11:00 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}` +); + From c57d66474b972ced601b3309981f0c2f4a6c26a1 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 13:20:57 +0000 Subject: [PATCH 26/29] restore sprint-2 from origin/main --- Sprint-2/1-key-errors/0.js | 18 ++---- Sprint-2/1-key-errors/1.js | 26 +++------ Sprint-2/1-key-errors/2.js | 19 ++----- Sprint-2/2-mandatory-debug/0.js | 18 ++---- Sprint-2/2-mandatory-debug/1.js | 8 +-- Sprint-2/2-mandatory-debug/2.js | 32 ++++------- Sprint-2/3-mandatory-implement/1-bmi.js | 5 +- Sprint-2/3-mandatory-implement/2-cases.js | 12 ---- Sprint-2/3-mandatory-implement/3-to-pounds.js | 12 ---- Sprint-2/4-mandatory-interpret/time-format.js | 12 ++-- Sprint-2/5-stretch-extend/format-time.js | 55 ------------------- 11 files changed, 45 insertions(+), 172 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 9fbe83452..653d6f5a0 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,23 +1,13 @@ // Predict and explain first... -// =============> I predict that we will not need to write let in line 8 as str is already declared -// as an argument within the function captialise. +// =============> write your prediction here // 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; -// } - -// capitalise ('hello'); -//==============> A syntaxError occurred as 'str' is being cleared. - - function capitalise(str) { - str = `${str[0].toUpperCase()}${str.slice(1)}`; + let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -console.log (capitalise ('hello')); - +// =============> write your explanation here +// =============> write your new code here diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 44f4fa8ff..f2d56151f 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,32 +1,20 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement. -// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. +// =============> write your prediction here // Try playing computer with the example to work out what is going on -// function convertToPercentage(decimalNumber) { - // const decimalNumber = 0.5; - // const percentage = `${decimalNumber * 100}%`; - - // return percentage; -//} - -// console.log(decimalNumber); - -// =============> A syntaxError occurred saying decimalNumber is already declared. - -// Finally, correct the code to fix the problem -// =============> write your new code here - -function convertToPercentage() { +function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(convertToPercentage()); +console.log(decimalNumber); + +// =============> write your explanation here -// the new code runs without error and outputs "50%" +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 3438e406c..aad57f7cf 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,25 +3,18 @@ // this function should square any number but instead we're going to get an error -// =============> The num parameter should be mentioned inside the function square instead of the number 3. -// then it should be called as square (3) in the console.log statement. +// =============> write your prediction of the error here -//function square(3) { -//return num * num; -//} - -// =============> function square(3) syntaxError: Unexpected number. -// =============> 3 wasn't expected... instead a declaration like 'num' was expected. +function square(3) { + return num * num; +} +// =============> write the error message here +// =============> explain this error message here // 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 9acb66bbf..b27511b41 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,20 +1,14 @@ // Predict and explain first... -// =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better -//because the console.log would only print a*b. +// =============> write your prediction here -//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)}`); -// =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined' -// as the multiply parameters weren't considered as parameters inside the function multiply. +// =============> write your explanation here // 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)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 626b920e7..37cedfbcf 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,13 @@ // Predict and explain first... -// =============> SyntaxError will occur due to putting a semicolon after return. +// =============> write your prediction here function sum(a, b) { - return a + b; + return; + a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'. +// =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here -// we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 7c2a6f004..57d3f5dc3 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,34 +1,24 @@ // Predict and explain first... // Predict the output of the following code: -// =============> The code will return 3 as a string first, but after calling the getLastDigit function, -// it will not return anything because every number based will be converted to string. +// =============> Write your prediction here -//const num = 103; +const num = 103; -//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 42 is 3 three times. -// the prediction was close but not accurate, the case is that the parameter num needs to be -//the function instead of const num = 103. -// =============> -// Finally, correct the code to fix the problem -// =============> write your new code here - -function getLastDigit(num) { +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 +// =============> 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 -// parameter num needs to be with the getLastDigit function instead of const num=103. diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 9c9ef7a4a..17b1cbde1 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,8 +15,5 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - const bmi = weight / (weight*height); - return bmi.toFixed(1); // return the BMI of someone based off their weight and height -} -console.log("the BMI is", calculateBMI(70, 1.73)); \ No newline at end of file +} \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 60c2682ce..5b0ef77ad 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,15 +14,3 @@ // 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 capSnakeCase(str) { - const upper = str.toUpperCase(); - const snake = upper.replace(/ /g, "_"); - return snake; -} -console.log(capSnakeCase("lord of the rings")); - -// step 1: get a string input -//step 2: change the upper case -//step 3: replace spaces with underscores -// step 4: return capSnakeCase \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index f340ad1e0..6265a1a70 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,15 +4,3 @@ // 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("399p")) -console.log(toPounds("5p")) -console.log(toPounds("5678p")) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 5a6489af9..7c98eb0e8 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,25 +10,25 @@ 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? -// =============> It will be called 3 times. +// =============> write your answer here // 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? -// =============> 0 +// =============> write your answer here // c) What is the return value of pad is called for the first time? -// =============> 00 +// =============> 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 -// =============> The leftover second is assigned to num as remainingSEconds 61%60 +// =============> 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 the remainingSeconds from passed from pad to num is changed to string and padded as 01 +// =============> write your answer here diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 90c475a37..32a32e66b 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,58 +23,3 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); - -const currentOutput3 = formatAs12HourClock("00:00"); -const targetOutput3 = "12:00 am"; -console.assert( - currentOutput3 === targetOutput3, - `current output: ${currentOutput3}, target output: ${targetOutput3}` -); - -const currentOutput4 = formatAs12HourClock("12:00"); -const targetOutput4 = "12:00 pm"; -console.assert( - currentOutput4 === targetOutput4, - `current output: ${currentOutput4}, target output: ${targetOutput4}` -); - -const currentOutput5 = formatAs12HourClock("13:00"); -const targetOutput5 = "1:00 pm"; -console.assert( - currentOutput5 === targetOutput5, - `current output: ${currentOutput5}, target output: ${targetOutput5}` -); - -const currentOutput7 = formatAs12HourClock("25:00"); -const targetOutput7 = "01:00 am"; -console.assert( - currentOutput7 === targetOutput7, - `current output: ${currentOutput7}, target output: ${targetOutput7}` -); - -// modified code: - -function formatAs12HourClock(time) { - let hours = Number(time.slice(0, 2)); - const minutes = time.slice(3); - - let suffix; - if (hours >= 12) { - suffix = "pm"; - - } else { - suffix = "am"; - } - hours = hours % 12 || 12; // Convert 0 to 12, 13 to 1 - const formattedHours = hours.toString().padStart(2, '0'); - - return `${formattedHours}:${minutes} ${suffix}`; -} - -const currentOutput6 = formatAs12HourClock("23:00"); -const targetOutput6 = "11:00 pm"; -console.assert( - currentOutput6 === targetOutput6, - `current output: ${currentOutput6}, target output: ${targetOutput6}` -); - From 9bf4964846695d4c0f97513f1cd6291d3c7354f0 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 13:26:01 +0000 Subject: [PATCH 27/29] deleted number-game-errors.html --- number-game-errors.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 number-game-errors.html diff --git a/number-game-errors.html b/number-game-errors.html deleted file mode 100644 index e69de29bb..000000000 From d868527345243f359caf89c11fa79e4e41a3d4e1 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 13:45:54 +0000 Subject: [PATCH 28/29] updated answers for 1-count.js and 3-path.js --- Sprint-1/1-key-exercises/1-count.js | 2 +- Sprint-1/1-key-exercises/3-paths.js | 10 +++++----- Sprint-1/1-key-exercises/4-random.js | 12 ------------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index b6b3bb43f..22195a4db 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,4 @@ 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 returns the incurmented value of count after adding 1 to it and assigns this new value back to count \ No newline at end of file +// line 3 is an assignment which returns the incurmented value of count after adding 1 to it. \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 80cc0a561..9856239a5 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -11,14 +11,14 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log (the base part of ${filePath} is ${base}); +const base = filePath.slice(lastSlashIndex + 1); // file.txt +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 = filePath.slice(lastSlashIndex+1) -const ext = filePath.slice(lastDotIndexOf(".") +1); +const dir = filePath.slice(0, lastSlashIndex) +const ext = filePath.slice(filePath.lastIndexOf(".")); -console.log (dir) +console.log (dir, ext) // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 7da6c30bc..5fb2d77db 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -9,16 +9,4 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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); \ No newline at end of file From 9b9dc8e7f8304f3799b17d88cb71c68585bc67c5 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 14:10:21 +0000 Subject: [PATCH 29/29] answering the task --- Sprint-1/1-key-exercises/4-random.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 5fb2d77db..bfa5de973 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -8,5 +8,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 +//num represents the results of equations at the right side of operator = + +//step-1---> Math.random() generates a random decimal. +//step-2---> (maximum - minimum + 1) evaluates to 100. +//step-3---> Math.random() is multiplied by (maximum - minimum + 1) which is 100, resulting in a random decimal between 0 and 100. +//step-4---> the result of Step-3 is round by the method Math.floor. +//step-5---> minimum is added to the result of step-4. +//Therefore, num represents random numbers generated between minimum 1 and maximum 100, as we run the code several times +//generates new numbers. console.log(num); \ No newline at end of file