From 522d1bd35f2fc9bacc626f1140bef164813412f6 Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Mon, 2 Mar 2026 13:39:16 +0000 Subject: [PATCH 1/5] Completion of Sprint 1 Coursework --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 2 ++ Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- Sprint-1/2-mandatory-errors/0.js | 7 +++++-- Sprint-1/2-mandatory-errors/1.js | 7 +++++++ Sprint-1/2-mandatory-errors/2.js | 8 ++++++++ Sprint-1/2-mandatory-errors/3.js | 8 ++++++++ Sprint-1/2-mandatory-errors/4.js | 11 ++++++++++- .../3-mandatory-interpret/1-percentage-change.js | 9 +++++---- Sprint-1/3-mandatory-interpret/2-time-format.js | 11 ++++++----- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 9 +++++++++ Sprint-1/4-stretch-explore/chrome.md | 7 +++++++ Sprint-1/4-stretch-explore/objects.md | 12 +++++++++--- 13 files changed, 82 insertions(+), 17 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..19f2fe950 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 is adding 1 to the initial values of count which is 0 and reassing the new value (1+0 =1) to count diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..c992d4d58 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -6,6 +6,8 @@ let lastName = "Johnson"; // 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 = ``; +initials = firstName.substring(0, 1) + middleName.substring(0, 1) + lastName.substring(0, 1) +console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..216e4fbdf 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,10 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.substring(0, 44); +console.log(`The dir part of the filePath variable is ${dir}`); +const lastDotIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDotIndex + 1); +console.log(`The ext of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ 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..fd81664bc 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? + +//ANSWER: +//We change the two lines to comments by using double forward slash (//) at the beginning of the two lines. diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..117eac0f1 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,10 @@ const age = 33; age = age + 1; + +// ANSWER +// In the solution above, 'age' is a constant variable becuse the keyword 'const' was used with it hence the value cannot change. + +// Solution: +let age = 33; +let age = age + 1; \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..53408c61c 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,11 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +//ANSWER: +// The 'cityOfBirth' was not assigned before the console.log statement +// Solution will be to switch the lines as shown below: + + +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..a2e630b4e 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -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 + +//Predcition: slice() probably only work on string. Possible solution will be to put cardNumber in quotes or use String() +// Why does it give this error? It says 'cardNumber.slice is not a function' +// Is this what I predicted? No +// If not, what's different? Since cardNumber is numeric, it shoulf be changed to string fot slice() to work. + +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..ea2dc8924 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,11 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; + +//In naming variable, numbers are not allowed to preceed variable names. + +// Error message: An identifier or keyword cannot immediately follow a numeric literal. + +// SUggested Solutions: + +const ClockTime12Hour = "20:53"; +const ClockTime24hour = "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..74833464f 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 - +//ANSWER: Four function calls. Two function calls in line 4 & two function calls in line 5 // 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? - +//ANSWER: The comma in the replaceAll() function in Line 5 is missing. Put the comma back in to fix it. // c) Identify all the lines that are variable reassignment statements - +//ANSWER: Lines that are variable reassignment statements are Lines 4 & 5. // d) Identify all the lines that are variable declarations - +//ANSWER: Variable declarations line: 1,2,7,& 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//ANSWER: The expression first removes the comma(,) in carPrice and then converts it to a number. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..214b3e5ef 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? - +//ANSWER: There were six variable declarations // b) How many function calls are there? - +//ANSWER: There were no function calls except for the log() function // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - +//ANSWER: The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +//ANSWER: Line 4 with find the remainder whenmovieLength is divided by 60 and assigns the remainder to remainingSeconds (24) // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//ANSWER: The variable result represents the total lenth of the movie which shows the total hours, minutes and seconds remain in string format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//ANSWER: The code semed to work for all values of movieLength. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..2d6553c31 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,12 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. Lines 3 to 6: extracts "399" as a string and assigns the values to penceStringWithoutTrailingP. +// It uses the substring to extract from position 0 to 3. +// 3. Line 8: padStart is used to pad the values in penceStringWithoutTrailingP with "0" from the start of the value to make up a length of 3. +// Since penceStringWithoutTrailingP already has "399" with a length of 3, no padding is done. +// 4. Line 9 to 12: substring is used to extract from paddedPenceNumberString, starting from position 0 to 1 giving 3 which is stored in the variable pounds. +// 5. Line 14 to 16: substring is used to extract from paddedPenceNumberString, starting from position 1 to the end givin "99" +// "99" is padded with "0" from the end of the value to make a length of 2 but sincw "99" already has a length of 2, no padding is done. +// "99" is assigned to the variable pence. +// 6. Line 18: uses console.log() to print the values of pounds and pence preceeded by "£" and separated by "." to give "£3.99" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..bddd08b8a 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,15 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +## Got "chrome://new-tab-page says" popup +## Hello world! Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? +## Got "chrome://new-tab-page says" popup +## Got "What is your name?" +## Got a box for input What is the return value of `prompt`? +## promt: ƒ prompt() { [native code] } +## myName: Ayo diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..62c3a9e41 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -4,13 +4,19 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter -What output do you get? +What output do you get? +## ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? - +## console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` - +## 'object' Answer the following questions: What does `console` store? +## Objects +## console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +## console.log - Prints the text to the Console as a log message +## console.assert() writes an error message to the console if the assertion is false +## The dot(.) allows the access of the log method inside the console object \ No newline at end of file From 0e99abce8a749d4248c41eb07730aebc5e9851cd Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Fri, 6 Mar 2026 15:45:09 +0000 Subject: [PATCH 2/5] Revert "Completion of Sprint 1 Coursework" This reverts commit 522d1bd35f2fc9bacc626f1140bef164813412f6. --- Sprint-1/1-key-exercises/1-count.js | 1 - Sprint-1/1-key-exercises/2-initials.js | 2 -- Sprint-1/1-key-exercises/3-paths.js | 7 ++----- Sprint-1/2-mandatory-errors/0.js | 7 ++----- Sprint-1/2-mandatory-errors/1.js | 7 ------- Sprint-1/2-mandatory-errors/2.js | 8 -------- Sprint-1/2-mandatory-errors/3.js | 8 -------- Sprint-1/2-mandatory-errors/4.js | 11 +---------- .../3-mandatory-interpret/1-percentage-change.js | 9 ++++----- Sprint-1/3-mandatory-interpret/2-time-format.js | 11 +++++------ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 9 --------- Sprint-1/4-stretch-explore/chrome.md | 7 ------- Sprint-1/4-stretch-explore/objects.md | 12 +++--------- 13 files changed, 17 insertions(+), 82 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 19f2fe950..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,3 @@ 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 is adding 1 to the initial values of count which is 0 and reassing the new value (1+0 =1) to count diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index c992d4d58..47561f617 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -6,8 +6,6 @@ let lastName = "Johnson"; // 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 = ``; -initials = firstName.substring(0, 1) + middleName.substring(0, 1) + lastName.substring(0, 1) -console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 216e4fbdf..ab90ebb28 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,10 +17,7 @@ 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.substring(0, 44); -console.log(`The dir part of the filePath variable is ${dir}`); +const dir = ; +const ext = ; -const lastDotIndex = filePath.lastIndexOf("."); -const ext = filePath.slice(lastDotIndex + 1); -console.log(`The ext of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ 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 fd81664bc..cf6c5039f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,5 +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? - -//ANSWER: -//We change the two lines to comments by using double forward slash (//) at the beginning of the two lines. +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 diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 117eac0f1..7a43cbea7 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,10 +2,3 @@ const age = 33; age = age + 1; - -// ANSWER -// In the solution above, 'age' is a constant variable becuse the keyword 'const' was used with it hence the value cannot change. - -// Solution: -let age = 33; -let age = age + 1; \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 53408c61c..e09b89831 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,11 +3,3 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; - -//ANSWER: -// The 'cityOfBirth' was not assigned before the console.log statement -// Solution will be to switch the lines as shown below: - - -const cityOfBirth = "Bolton"; -console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index a2e630b4e..ec101884d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,11 +7,3 @@ 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 - -//Predcition: slice() probably only work on string. Possible solution will be to put cardNumber in quotes or use String() -// Why does it give this error? It says 'cardNumber.slice is not a function' -// Is this what I predicted? No -// If not, what's different? Since cardNumber is numeric, it shoulf be changed to string fot slice() to work. - -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 ea2dc8924..21dad8c5d 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,11 +1,2 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; - -//In naming variable, numbers are not allowed to preceed variable names. - -// Error message: An identifier or keyword cannot immediately follow a numeric literal. - -// SUggested Solutions: - -const ClockTime12Hour = "20:53"; -const ClockTime24hour = "08:53"; \ No newline at end of file +const 24hourClockTime = "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 74833464f..e24ecb8e1 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,12 +12,11 @@ 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 -//ANSWER: Four function calls. Two function calls in line 4 & two function calls in line 5 + // 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? -//ANSWER: The comma in the replaceAll() function in Line 5 is missing. Put the comma back in to fix it. + // c) Identify all the lines that are variable reassignment statements -//ANSWER: Lines that are variable reassignment statements are Lines 4 & 5. + // d) Identify all the lines that are variable declarations -//ANSWER: Variable declarations line: 1,2,7,& 8 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -//ANSWER: The expression first removes the comma(,) in carPrice and then converts it to a number. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 214b3e5ef..47d239558 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,15 +12,14 @@ 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? -//ANSWER: There were six variable declarations + // b) How many function calls are there? -//ANSWER: There were no function calls except for the log() function + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -//ANSWER: The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -//ANSWER: Line 4 with find the remainder whenmovieLength is divided by 60 and assigns the remainder to remainingSeconds (24) + // e) What do you think the variable result represents? Can you think of a better name for this variable? -//ANSWER: The variable result represents the total lenth of the movie which shows the total hours, minutes and seconds remain in string format. + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -//ANSWER: The code semed to work for all values of movieLength. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 2d6553c31..60c9ace69 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,12 +25,3 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" -// 2. Lines 3 to 6: extracts "399" as a string and assigns the values to penceStringWithoutTrailingP. -// It uses the substring to extract from position 0 to 3. -// 3. Line 8: padStart is used to pad the values in penceStringWithoutTrailingP with "0" from the start of the value to make up a length of 3. -// Since penceStringWithoutTrailingP already has "399" with a length of 3, no padding is done. -// 4. Line 9 to 12: substring is used to extract from paddedPenceNumberString, starting from position 0 to 1 giving 3 which is stored in the variable pounds. -// 5. Line 14 to 16: substring is used to extract from paddedPenceNumberString, starting from position 1 to the end givin "99" -// "99" is padded with "0" from the end of the value to make a length of 2 but sincw "99" already has a length of 2, no padding is done. -// "99" is assigned to the variable pence. -// 6. Line 18: uses console.log() to print the values of pounds and pence preceeded by "£" and separated by "." to give "£3.99" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index bddd08b8a..e7dd5feaf 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,15 +11,8 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? -## Got "chrome://new-tab-page says" popup -## Hello world! Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? -## Got "chrome://new-tab-page says" popup -## Got "What is your name?" -## Got a box for input What is the return value of `prompt`? -## promt: ƒ prompt() { [native code] } -## myName: Ayo diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 62c3a9e41..0216dee56 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -4,19 +4,13 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter -What output do you get? -## ƒ log() { [native code] } +What output do you get? Now enter just `console` in the Console, what output do you get back? -## console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + Try also entering `typeof console` -## 'object' + Answer the following questions: What does `console` store? -## Objects -## console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? -## console.log - Prints the text to the Console as a log message -## console.assert() writes an error message to the console if the assertion is false -## The dot(.) allows the access of the log method inside the console object \ No newline at end of file From 049b7e511b982480b9c82a273d23788bd5c111e7 Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Sun, 8 Mar 2026 14:46:50 +0000 Subject: [PATCH 3/5] Completion of tasks in 2-practice-tdd --- Sprint-3/2-practice-tdd/count.js | 10 ++++++++-- Sprint-3/2-practice-tdd/get-ordinal-number.js | 14 +++++++++++++- Sprint-3/2-practice-tdd/repeat-str.js | 4 ++-- i | 7 +++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 i diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..c377378c9 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + let count = 0; + for (let i = 0; i < str.length; i++) { + if (str[i] === char) { + count++; + } + } + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..b0aeaba47 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,17 @@ function getOrdinalNumber(num) { - return "1st"; + nonStr = num.toString(); + if (nonStr.endsWith("1") && nonStr !== "11") { + return nonStr.concat("st"); + } else if (nonStr.endsWith("2")) { + return nonStr.concat("nd"); + } else if (nonStr.endsWith("3")) { + return nonStr.concat("rd"); + } else { + return "Invalid"; + } + } module.exports = getOrdinalNumber; + + diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..7850fb691 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,5 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + return str.repeat(count); } module.exports = repeatStr; diff --git a/i b/i new file mode 100644 index 000000000..577d956ee --- /dev/null +++ b/i @@ -0,0 +1,7 @@ +* 1-implement-and-rewrite-tests + 3-dead-code + Sprint-3/2-practice-tdd + acoursework/sprint-2 + acoursework/sprint-2_old + coursework/sprint-3-implement-and-rewrite + main From bd63db0380d2f48984836f33123298d911fe9e76 Mon Sep 17 00:00:00 2001 From: Ayodeji_Ayorinde26 Date: Wed, 11 Mar 2026 19:01:14 +0000 Subject: [PATCH 4/5] Delete i Deleted file i, not sure how it got added --- i | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 i diff --git a/i b/i deleted file mode 100644 index 577d956ee..000000000 --- a/i +++ /dev/null @@ -1,7 +0,0 @@ -* 1-implement-and-rewrite-tests - 3-dead-code - Sprint-3/2-practice-tdd - acoursework/sprint-2 - acoursework/sprint-2_old - coursework/sprint-3-implement-and-rewrite - main From 1e235e947d40e4a3bbb0da8808476e509970a73b Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Sat, 18 Apr 2026 15:44:10 +0100 Subject: [PATCH 5/5] Redo of ttd --- Sprint-3/2-practice-tdd/count.js | 16 ++++-- Sprint-3/2-practice-tdd/count.test.js | 37 +++++++++++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 30 +++++++---- .../2-practice-tdd/get-ordinal-number.test.js | 52 +++++++++++++------ Sprint-3/2-practice-tdd/repeat-str.js | 15 ++++++ Sprint-3/2-practice-tdd/repeat-str.test.js | 47 +++++++++++++++++ 6 files changed, 170 insertions(+), 27 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index c377378c9..957a28f06 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,11 +1,21 @@ + + +/** + * Counts the occurrences of a character within a string. + * @param {string} str - The string to search through. + * @param {string} char - The character to look for. + * @returns {number} - The total count of the character. + */ function countChar(str, char) { let count = 0; - for (let i = 0; i < str.length; i++) { - if (str[i] === char) { + + for (const letter of str) { + if (letter === char) { count++; } } + return count; } -module.exports = countChar; +module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..e8552f8cc 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,5 +1,10 @@ // implement a function countChar that counts the number of times a character occurs in a string + +/* const countChar = require("./count"); +*/ + + // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: @@ -10,15 +15,47 @@ const countChar = require("./count"); // When the function is called with these inputs, // Then it should correctly count occurrences of `char`. +/* test("should count multiple occurrences of a character", () => { const str = "aaaaa"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(5); }); +*/ // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. + + + +const countChar = require("./count"); + +describe("countChar function", () => { + // Scenario: Multiple Occurrences + test("should count multiple occurrences of a character", () => { + const str = "aaaaa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); + }); + + // Scenario: No Occurrences + test("should return 0 when the character does not exist in the string", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); + }); + + // Bonus Scenario: Mixed Case (Character searching is case-sensitive) + test("should be case-sensitive", () => { + const str = "Abba"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(1); // Only the lowercase 'a' is counted + }); +}); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index b0aeaba47..ce1b53ac5 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,17 +1,29 @@ + + function getOrdinalNumber(num) { - nonStr = num.toString(); - if (nonStr.endsWith("1") && nonStr !== "11") { - return nonStr.concat("st"); - } else if (nonStr.endsWith("2")) { - return nonStr.concat("nd"); - } else if (nonStr.endsWith("3")) { - return nonStr.concat("rd"); - } else { - return "Invalid"; + const s = num.toString(); + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + // Rule for 11th, 12th, 13th (The "Teens" exception) + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return s + "th"; } + // Standard rules based on the last digit + switch (lastDigit) { + case 1: + return s + "st"; + case 2: + return s + "nd"; + case 3: + return s + "rd"; + default: + return s + "th"; + } } + module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560..b70074494 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,20 +1,42 @@ + const getOrdinalNumber = require("./get-ordinal-number"); -// In this week's prep, we started implementing getOrdinalNumber. -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. +describe("getOrdinalNumber", () => { + // Case 1: Numbers ending with 1 (but not 11) + test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(1)).toBe("1st"); + expect(getOrdinalNumber(21)).toBe("21st"); + expect(getOrdinalNumber(101)).toBe("101st"); + }); + + // Case 2: Numbers ending with 2 (but not 12) + test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toBe("2nd"); + expect(getOrdinalNumber(42)).toBe("42nd"); + expect(getOrdinalNumber(122)).toBe("122nd"); + }); + + // Case 3: Numbers ending with 3 (but not 13) + test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toBe("3rd"); + expect(getOrdinalNumber(53)).toBe("53rd"); + expect(getOrdinalNumber(1003)).toBe("1003rd"); + }); -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// Instead of writing tests for individual numbers, consider grouping all possible input values -// into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. + // Case 4: The Teen Exceptions (11, 12, 13) + test("should append 'th' for numbers ending in 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + expect(getOrdinalNumber(13)).toBe("13th"); + expect(getOrdinalNumber(111)).toBe("111th"); // Edge case: triple digits + }); -// Case 1: Numbers ending with 1 (but not 11) -// When the number ends with 1, except those ending with 11, -// Then the function should return a string by appending "st" to the number. -test("should append 'st' for numbers ending with 1, except those ending with 11", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - expect(getOrdinalNumber(21)).toEqual("21st"); - expect(getOrdinalNumber(131)).toEqual("131st"); + // Case 5: All other numbers (Ending in 0, 4, 5, 6, 7, 8, 9) + test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(0)).toBe("0th"); + expect(getOrdinalNumber(4)).toBe("4th"); + expect(getOrdinalNumber(9)).toBe("9th"); + expect(getOrdinalNumber(10)).toBe("10th"); + expect(getOrdinalNumber(20)).toBe("20th"); + }); }); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 7850fb691..a1d68fccb 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,4 +1,19 @@ + + +/** + * Repeats a string a given number of times. + * @param {string} str - The string to repeat. + * @param {number} count - The number of times to repeat the string. + * @returns {string} - The repeated string. + * @throws {Error} - If count is a negative integer. + */ function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count must be a non-negative integer"); + } + + // If count is 0, .repeat(0) naturally returns an empty string "". + // If count is 1, .repeat(1) naturally returns the original string. return str.repeat(count); } diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..77bfbf9ba 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -1,5 +1,48 @@ + +const repeatStr = require("./repeat-str"); + +describe("repeatStr", () => { + // Case: handle multiple repetitions + test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohellohello"); + }); + + // Case: handle count of 1 + test("should return the original string when count is 1", () => { + const str = "apple"; + const count = 1; + expect(repeatStr(str, count)).toEqual("apple"); + }); + + // Case: Handle count of 0 + test("should return an empty string when count is 0", () => { + const str = "ghost"; + const count = 0; + expect(repeatStr(str, count)).toEqual(""); + }); + + // Case: Handle negative count + test("should throw an error when count is negative", () => { + const str = "error"; + const count = -1; + + // We wrap the call in a function so Jest can catch the error + expect(() => { + repeatStr(str, count); + }).toThrow("Count must be a non-negative integer"); + }); +}); + + // Implement a function repeatStr + +/* const repeatStr = require("./repeat-str"); +*/ + // Given a target string `str` and a positive integer `count`, // When the repeatStr function is called with these inputs, // Then it should: @@ -9,6 +52,7 @@ const repeatStr = require("./repeat-str"); // When the repeatStr function is called with these inputs, // Then it should return a string that contains the original `str` repeated `count` times. +/* test("should repeat the string count times", () => { const str = "hello"; const count = 3; @@ -16,6 +60,9 @@ test("should repeat the string count times", () => { expect(repeatedStr).toEqual("hellohellohello"); }); +*/ + + // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs,