From 522d1bd35f2fc9bacc626f1140bef164813412f6 Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Mon, 2 Mar 2026 13:39:16 +0000 Subject: [PATCH 1/4] 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/4] 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 1d8c408e290805eaefd2d7c0cb5ccc5ad1ed33da Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Fri, 6 Mar 2026 16:29:48 +0000 Subject: [PATCH 3/4] Completion of Sprint 2 tasks --- Sprint-2/1-key-errors/0.js | 9 +++++++-- Sprint-2/1-key-errors/1.js | 9 ++++++--- Sprint-2/1-key-errors/2.js | 12 +++++++---- Sprint-2/2-mandatory-debug/0.js | 7 +++++-- Sprint-2/2-mandatory-debug/1.js | 8 ++++++-- Sprint-2/2-mandatory-debug/2.js | 16 ++++++++++++--- Sprint-2/3-mandatory-implement/1-bmi.js | 1 + Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 20 +++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++----- 10 files changed, 75 insertions(+), 21 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..2c0ec877e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> Prediction: The function capitalise is possibly meant to capitalise the first letter in a string. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +9,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here +// =============> =============> write your explanation here +// The 'str' variable on the left hand side is the same used in the function name implementation which should not be. // =============> write your new code here +function capitalise(str) { + let capFunction = `${str[0].toUpperCase()}${str.slice(1)}`; + return capFunction; +} \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..fef6a3cad 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? -// =============> write your prediction here +// =============> I suspect than an error will occur // Try playing computer with the example to work out what is going on @@ -14,7 +14,10 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here - +// =============> write your explanation here. The functions takes a decimal number as input and converts it to percentage by multiplying by 100 // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..f5021c8a5 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,22 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here. The error is likely to be caused by square(3), '3' is supposed to be replaced by a string representing the number. function square(3) { return num * num; } // =============> write the error message here - +// function square(3) { +// ^ +// SyntaxError: Unexpected number // =============> explain this error message here - +// The muber '3' should be used when calling the function and it should not be used as a parameter. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..451ba98c5 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here. It may likely have issues as console.log() is within function implementation, instead of using'return' function multiply(a, b) { console.log(a * b); @@ -8,7 +8,10 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here. Instead of having console.log() is within function implementation, it should be replaced with 'return' // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + return (a * b); +} \ 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 37cedfbcf..9c8926d7a 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here. An error will result becasue of the ';' between return and a + b + function sum(a, b) { return; @@ -8,6 +9,9 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here. The ideal statement should be 'return a + b; ' but this statement is separated by ';' // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} \ 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 57d3f5dc3..47aba7d87 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,8 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here. It may run but give incorrect results because of const num & no parameter specified + const num = 103; @@ -15,10 +16,19 @@ 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 +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 // Explain why the output is the way it is -// =============> write your explanation here +// =============> write your explanation here. num is a constant variable, it's value cannot change. // Finally, correct the code to fix the problem // =============> write your new code here - +function getLastDigit() { + return num.toString().slice(-1); +} // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// getLastDigit is not working properly because the value for num is fixed at '103' +function getLastDigit(num) { + return num.toString().slice(-1); +} diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..a0c825b4c 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,5 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height + return Math.round((weight) / (height ** 2)).toFixed(1) } \ 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 5b0ef77ad..bdf32e61a 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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 upCase(strCar) { + let result = strCar.toUpperCase().replaceAll(" ", "_"); + return result; +} diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..bb2ad2739 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,23 @@ // 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(money) { + const moneyWithoutTrailingP = money.substring( + 0, + money.length - 1 + ); + const paddedPenceNumberString = moneyWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + result = pounds + "." + pence; + res = `£${pounds}.${pence}`; + return res; +} +console.log(toPounds("399p")) +console.log(toPounds("1099p")) \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..ebaf68ef1 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here.pad will be called three 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 +// =============> write your answer here. the value assigned to num when pad is called for the first time is 00 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> write your answer here. the return value of pad is called for the first time is '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 +// =============> write your answer here. the value assigned to num when pad is called for the last time is 01 // 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 +// =============> write your answer here. the return value assigned to num when pad is called for the last time in this program is '01' From 11ee71c705b106d0edc11ded3757b3a7b267d4b1 Mon Sep 17 00:00:00 2001 From: Ayodeji Ayorinde Date: Wed, 15 Apr 2026 19:10:25 +0100 Subject: [PATCH 4/4] Sprint 2 redone --- Sprint-2/2-mandatory-debug/2.js | 34 +++++++++++++----- Sprint-2/3-mandatory-implement/1-bmi.js | 13 +++++-- Sprint-2/3-mandatory-implement/2-cases.js | 14 ++++++-- Sprint-2/3-mandatory-implement/3-to-pounds.js | 35 ++++++++++++++----- Sprint-2/4-mandatory-interpret/time-format.js | 15 +++++--- 5 files changed, 83 insertions(+), 28 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 47aba7d87..735bb2e6d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,9 @@ // Predict and explain first... + // Predict the output of the following code: -// =============> Write your prediction here. It may run but give incorrect results because of const num & no parameter specified +// =============> Write your prediction here. +// //ANS: To return the last digit of num as a string. const num = 103; @@ -20,15 +22,31 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); // The last digit of 105 is 3 // The last digit of 806 is 3 // Explain why the output is the way it is -// =============> write your explanation here. num is a constant variable, it's value cannot change. +// =============> write your explanation here. +// //ANS: +// num is a constant variable, a hardcoded reference. +//The function getLastDigit is currently ignoring the arguments you pass to it(42, 105, 806) because of two main issues: + +//Missing Parameter: The function definition function getLastDigit() does not have a parameter inside the parentheses.In JavaScript, if you pass an argument to a function that hasn't defined a parameter to receive it, the function simply ignores that input. + +//Scope and Variable Reference: Inside the function, you are explicitly calling num.toString().Since num isn't defined inside the function, the engine looks at the Global Scope, finds const num = 103, and uses that value every single time the function runs. + // Finally, correct the code to fix the problem // =============> write your new code here -function getLastDigit() { - return num.toString().slice(-1); +const num = 103; // This is now ignored by the function + +// We add 'n' as a parameter to "catch" the numbers we pass in +function getLastDigit(n) { + // We call toString() on 'n' instead of the global 'num' + return n.toString().slice(-1); } + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem -// getLastDigit is not working properly because the value for num is fixed at '103' -function getLastDigit(num) { - return num.toString().slice(-1); -} +//ANS: Done above. +// ANS:getLastDigit was not working properly because the value for num is fixed at '103' + diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index a0c825b4c..b598100a6 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,6 +15,13 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height - return Math.round((weight) / (height ** 2)).toFixed(1) -} \ No newline at end of file + // BMI = kg / m^2 + const bmi = weight / (height * height); + + // .toFixed(1) rounds to 1 decimal place and returns a string + return bmi.toFixed(1); +} + +// Example usage: +const myBMI = calculateBMI(70, 1.73); +console.log(`The calculated BMI is: ${myBMI}`); // Output: "23.4" \ 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 bdf32e61a..2e2a55a6a 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,7 +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 upCase(strCar) { - let result = strCar.toUpperCase().replaceAll(" ", "_"); - return result; + + +function toUpperSnakeCase(text) { + // 1. replaceAll(' ', '_') swaps every space for an underscore + // 2. toUpperCase() converts the letters to all caps + return text.replaceAll(' ', '_').toUpperCase(); } + +// Examples: +console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE" +console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS" +console.log(toUpperSnakeCase("javascript is fun")); // "JAVASCRIPT_IS_FUN" \ 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 bb2ad2739..075762f98 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,22 +5,39 @@ // You should call this function a number of times to check it works for different inputs -function toPounds(money) { - const moneyWithoutTrailingP = money.substring( +/** + * Converts a pence string (e.g., "399p") into a formatted pound string (e.g., "£3.99") + * @param {string} penceString - The input string ending in 'p' + */ +function toPounds(penceString) { + // 1. Remove the trailing 'p' + const penceStringWithoutTrailingP = penceString.substring( 0, - money.length - 1 + penceString.length - 1 ); - const paddedPenceNumberString = moneyWithoutTrailingP.padStart(3, "0"); + + // 2. Pad with leading zeros to ensure at least 3 characters (e.g., "5p" -> "005") + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + // 3. Extract the pounds (everything except the last two digits) const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); + + // 4. Extract the pence (the last two digits) const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); - result = pounds + "." + pence; - res = `£${pounds}.${pence}`; - return res; + + // 5. Return the formatted string + return `£${pounds}.${pence}`; } -console.log(toPounds("399p")) -console.log(toPounds("1099p")) \ No newline at end of file + +// --- Testing the function with different inputs --- + +console.log(toPounds("399p")); // Expected: £3.99 +console.log(toPounds("50p")); // Expected: £0.50 +console.log(toPounds("1250p")); // Expected: £12.50 +console.log(toPounds("8p")); // Expected: £0.08 +console.log(toPounds("1002p")); // Expected: £10.02 \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index ebaf68ef1..a8b118bca 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,23 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here.pad will be called three times. +// =============> write your answer here. +// //ANS: 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. the value assigned to num when pad is called for the first time is 00 +// =============> write your answer here. +// ANS: the value assigned to num when pad is called for the first time is 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here. the return value of pad is called for the first time is '00' +// =============> write your answer here. +// //ANS: the return value of pad is called for the first time is '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 value assigned to num when pad is called for the last time is 01 +// =============> write your answer here. +// ANS: the value assigned to num when pad is called for the last time is 1 // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here. the return value assigned to num when pad is called for the last time in this program is '01' +// =============> write your answer here. +// ANS: Sthe return value assigned to num when pad is called for the last time in this program is '01'