From db4dc5d03028d8af176305149efa96cf9d9b5ac1 Mon Sep 17 00:00:00 2001 From: risikatpopoola Date: Wed, 1 Jul 2026 15:36:24 +0100 Subject: [PATCH 1/9] new coursework sprint 1 --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 7 +--- Sprint-1/1-key-exercises/3-paths.js | 4 ++ Sprint-1/1-key-exercises/4-random.js | 5 ++- Sprint-1/2-mandatory-errors/0.js | 4 +- Sprint-1/2-mandatory-errors/1.js | 3 +- Sprint-1/2-mandatory-errors/2.js | 2 + Sprint-1/2-mandatory-errors/3.js | 5 ++- Sprint-1/2-mandatory-errors/4.js | 4 +- .../1-percentage-change.js | 13 +++++-- .../3-mandatory-interpret/2-time-format.js | 11 +++--- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 8 +++- Sprint-1/4-stretch-explore/chrome.md | 3 ++ Sprint-1/4-stretch-explore/objects.md | 9 ++++- Sprint-2/4-mandatory-interpret/time-format.js | 38 ------------------- 15 files changed, 54 insertions(+), 63 deletions(-) delete mode 100644 Sprint-2/4-mandatory-interpret/time-format.js diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..d38f3ced13 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 +// In Line 3, count is a variable, and the = is an assignment operator that stores the result of the operation(Addition) \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..2c11be1be8 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -1,11 +1,8 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -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 = ``; +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 - diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..c26e4a8f07 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -20,4 +20,8 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = ; const ext = ; +const dir =filePath.slice(0, filePath.lastIndexOf("/")+1); +const ext =filePath.slice(filePath.indexOf(".")+1); +console.log(dir) +console.log(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 292f83aabb..95623a8ec9 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,9 +1,12 @@ -const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +console.log(num) // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing +//The math.Floor method rounds a number to the nearest integer, so using bodmas, +//the expressions are evaluated, the minimum which equals 1 is added to 1 then subtracted from maximum(100), after which it is multiplied by +//a random number between 0-1 exclusive and then rounded down to the nearest integer after which the minimum is added. The values produced ranges from 0-100 \ 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 cf6c5039f7..65ad3030d6 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 diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..0ba75ba699 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 const age = 33; -age = age + 1; +let age = 33; +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 e09b89831d..789b28d090 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,4 +2,6 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); +// what's the error ? You cannot access a variable before initialization. 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 ec101884db..43a890b102 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,10 @@ const cardNumber = 4533787178994213; +const cardNumber = '4533787178994213'; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber -// However, the code isn't working -// Before running the code, make and explain a prediction about why the code won't work +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 didn't work because the method only works for strings so to make it work the card number should be saved as a string. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..624013fe81 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const TwelveHourClockTime = "8:53pm"; +const TwentyFourHourClockTime = "20:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..b1b6395512 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -3,20 +3,27 @@ let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +carPrice = Number(carPrice.replaceAll(",","")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; - 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 +//The function call are made five times +//line 4, 5, 10 + // 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? +// Line 5, it was missing a comma between the characters that are to be replaced so to fix the problem, include a comma + // c) Identify all the lines that are variable reassignment statements +//Lines 7 & 8 // d) Identify all the lines that are variable declarations - +//Lines 1 & 2 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//This expression replaces every instance of "," with "". \ 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 47d2395587..e64acadab0 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -9,17 +9,18 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; console.log(result); -// For the piece of code above, read the code and then answer the following questions - // a) How many variable declarations are there in this program? - +//6 // b) How many function calls are there? - -// c) Using documentation, explain what the expression movieLength % 60 represents +//1 +// c) Using documentation, explain what the expression movieLength % 60 represents it represents the remainder when movielength is divided by 60 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//The expression assigned to totalMinutes means that the remaining seconds are subtracted from the movieLength and then divided by 60 to get the total number of minutes in the movie length. // e) What do you think the variable result represents? Can you think of a better name for this variable? +//The variable result represents the total time of the movie, in hours minutes and seconds. A better name for this variable could be totaltime // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//Yes it would work, we have accommodated for all length \ 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 60c9ace69a..f935d926dd 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,19 +1,23 @@ const penceString = "399p"; +//initializes a string variable with the value "399p" const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); - +//initializes a string variable by taking a substring of penceString up until the part where the p is, so without the p const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//it initializes a string variable by padding the start of the pencestringwithoutrailing with 0 if the length is less than 3 const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +//it initializes a string variable by taking all the strings except from the last two letters const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); + //initializes a string variable by taking a substring from paddedpencenumberstring except from the last two letters and padding the end wih 0, if it is less than 2 console.log(`£${pounds}.${pence}`); @@ -24,4 +28,4 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +// 1. const penceString = "399p": initializes a string variable with the value "399p" \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..6e0741b919 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -12,7 +12,10 @@ invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +A pop up notification saying 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? +It brings up a input tab to enter an answer What is the return value of `prompt`? +the input entered diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..01379d61df 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -1,16 +1,21 @@ ## Objects -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +undefined/ f log() native code Now enter just `console` in the Console, what output do you get back? +a list of all console types and how to use them Try also entering `typeof console` +object Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +What does `console` store? The console object provides access to the debugging console. It stores text and data explicitly sent to it using methods like console.log() or console.info() +What does the syntax `console.log` or `console.assert` mean? +The assert() method writes a message to the console if an expression evaluates to false. The log() method writes (logs) a message to the console. +In particular, what does the `.` mean? diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js deleted file mode 100644 index 17127bc01e..0000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,38 +0,0 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} - -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// Questions - -// a) When formatTimeDisplay is called how many times will pad be called? -// =============> 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? -// =============> write your answer here - -// c) What is the return value of pad is called for the first time? -// =============> 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 -// =============> write your answer here - -// e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here From f7ff8807bfae65d2df9867f0894d6ecc2f792530 Mon Sep 17 00:00:00 2001 From: risikatpopoola Date: Wed, 1 Jul 2026 15:59:38 +0100 Subject: [PATCH 2/9] restore accidentally deleted files --- Sprint-2/4-mandatory-interpret/time-format.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Sprint-2/4-mandatory-interpret/time-format.js diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js new file mode 100644 index 0000000000..17127bc01e --- /dev/null +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -0,0 +1,38 @@ +function pad(num) { + let numString = num.toString(); + while (numString.length < 2) { + numString = "0" + numString; + } + return numString; +} + +function formatTimeDisplay(seconds) { + const remainingSeconds = seconds % 60; + const totalMinutes = (seconds - remainingSeconds) / 60; + const remainingMinutes = totalMinutes % 60; + const totalHours = (totalMinutes - remainingMinutes) / 60; + + return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; +} + +// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit +// to help you answer these questions + +// Questions + +// a) When formatTimeDisplay is called how many times will pad be called? +// =============> 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? +// =============> write your answer here + +// c) What is the return value of pad is called for the first time? +// =============> 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 +// =============> write your answer here + +// e) What is the return value of pad when it is called for the last time in this program? Explain your answer +// =============> write your answer here From b610d6eb8fb659b59ac5ca2b144594075a9d9da9 Mon Sep 17 00:00:00 2001 From: risikatpopoola Date: Wed, 1 Jul 2026 19:22:37 +0100 Subject: [PATCH 3/9] sprint fix --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index b1b6395512..5e30e3a7f4 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); carPrice = Number(carPrice.replaceAll(",","")); priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); From bab774c3188bb88e1b0ad6296803d5f96a2d1512 Mon Sep 17 00:00:00 2001 From: Rizqah Date: Sun, 5 Jul 2026 08:42:42 +0100 Subject: [PATCH 4/9] issues resolved --- Sprint-1/1-key-exercises/1-count.js | 3 ++- Sprint-1/1-key-exercises/3-paths.js | 5 +---- Sprint-1/1-key-exercises/4-random.js | 4 ++-- Sprint-1/2-mandatory-errors/3.js | 4 +--- Sprint-1/2-mandatory-errors/4.js | 4 ++-- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 2 +- Sprint-1/3-mandatory-interpret/2-time-format.js | 2 +- Sprint-1/4-stretch-explore/chrome.md | 3 ++- Sprint-1/4-stretch-explore/objects.md | 1 + 9 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index d38f3ced13..7601e82f47 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,5 @@ 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 -// In Line 3, count is a variable, and the = is an assignment operator that stores the result of the operation(Addition) \ No newline at end of file +// In Line 3, count is a variable, and the = is an assignment operator that stores the result of the operation(Addition) +//Line 3 is incrementing the count variable by 1 \ 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 c26e4a8f07..24597e36c2 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 = ; -const ext = ; - -const dir =filePath.slice(0, filePath.lastIndexOf("/")+1); +const dir =filePath.slice(0, filePath.lastIndexOf("/")); const ext =filePath.slice(filePath.indexOf(".")+1); console.log(dir) console.log(ext) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 95623a8ec9..bc9c3fe543 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,5 +1,5 @@ +const minimum = 1; const maximum = 100; - const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; console.log(num) @@ -9,4 +9,4 @@ console.log(num) // Try logging the value of num and running the program several times to build an idea of what the program is doing //The math.Floor method rounds a number to the nearest integer, so using bodmas, //the expressions are evaluated, the minimum which equals 1 is added to 1 then subtracted from maximum(100), after which it is multiplied by -//a random number between 0-1 exclusive and then rounded down to the nearest integer after which the minimum is added. The values produced ranges from 0-100 \ No newline at end of file +//a random number between 0-1 exclusive and then rounded down to the nearest integer after which the minimum is added. The values of num produced ranges from 1-100 \ 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 43a890b102..5004790192 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,7 @@ const cardNumber = 4533787178994213; -const cardNumber = '4533787178994213'; -const last4Digits = cardNumber.slice(-4); +const last4Digits = String(cardNumber).slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber -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 diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 624013fe81..b0feba1bbc 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const TwelveHourClockTime = "8:53pm"; -const TwentyFourHourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 5e30e3a7f4..7cd56ef8a8 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -18,7 +18,7 @@ console.log(`The percentage change is ${percentageChange}`); // 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? -// Line 5, it was missing a comma between the characters that are to be replaced so to fix the problem, include a comma +// Line 5, A comma was missing between the arguments. Include a comma between the arguments to fix the error. // c) Identify all the lines that are variable reassignment statements //Lines 7 & 8 diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index e64acadab0..e7125bcf5f 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -20,7 +20,7 @@ console.log(result); //The expression assigned to totalMinutes means that the remaining seconds are subtracted from the movieLength and then divided by 60 to get the total number of minutes in the movie length. // e) What do you think the variable result represents? Can you think of a better name for this variable? -//The variable result represents the total time of the movie, in hours minutes and seconds. A better name for this variable could be totaltime +//The variable result represents the total time of the movie, in hours minutes and seconds. A better name for this variable could be totalTimeStr // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer //Yes it would work, we have accommodated for all length \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index 6e0741b919..ab27b76eb2 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -18,4 +18,5 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? It brings up a input tab to enter an answer What is the return value of `prompt`? -the input entered +the input entered and sent by pressing ok, else it would return null + diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 01379d61df..1f278bc989 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -19,3 +19,4 @@ What does `console` store? The console object provides access to the debugging c What does the syntax `console.log` or `console.assert` mean? The assert() method writes a message to the console if an expression evaluates to false. The log() method writes (logs) a message to the console. In particular, what does the `.` mean? +This is a Dot Notation, it is used to access an object's properties or methods From c412519d052d4f067c66e54fbe9971f39b3c5a1c Mon Sep 17 00:00:00 2001 From: Rizqah Date: Tue, 7 Jul 2026 22:39:05 +0100 Subject: [PATCH 5/9] implement and rewrite tests --- .../implement/1-get-angle-type.js | 49 +++++++++++++- .../implement/2-is-proper-fraction.js | 5 ++ .../implement/3-get-card-value.js | 67 ++++++++++++++++++- 3 files changed, 117 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..4e1bff06ae 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,6 +16,24 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90){ + return "Acute angle"; + } + else if (angle == 90){ + return "Right angle"; + } + else if (angle > 90 && angle < 180){ + return "Obtuse angle"; + } + else if (angle == 180){ + return "Straight angle"; + } + else if (angle > 180 && angle < 360){ + return "Reflex angle"; + } + else{ + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -32,6 +50,31 @@ function assertEquals(actualOutput, targetOutput) { } // TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); + +// Tests for right angles +assertEquals(getAngleType(90), "Right angle"); + +// Tests for acute angles +assertEquals(getAngleType(56), "Acute angle"); +assertEquals(getAngleType(1), "Acute angle"); + +// Test for a straight line +assertEquals(getAngleType(180), "Straight angle"); + +// Test for obtuse angle +assertEquals(getAngleType(95), "Obtuse angle"); +assertEquals(getAngleType(160), "Obtuse angle"); +assertEquals(getAngleType(102), "Obtuse angle"); + +// Test for reflex angle +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(249), "Reflex angle"); + +// Test for invalid angles +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(361), "Invalid angle"); +assertEquals(getAngleType(-980), "Invalid angle"); +assertEquals(getAngleType(90), "Right angle"); +assertEquals(getAngleType(672), "Invalid angle"); +console.log("Execution finished! If any test failed, console.assert errors will appear above."); + diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..77dc328283 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,6 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { + return numerator < denominator; // TODO: Implement this function } @@ -31,3 +32,7 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(93, 112), true); +assertEquals(isProperFraction(2, 1), false); +assertEquals(isProperFraction(80, 80), false); +console.log("Execution finished! If any test failed, console.assert errors will appear above."); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..a65871f335 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -23,8 +23,39 @@ function getCardValue(card) { // TODO: Implement this function + const ranks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + const suits = ["♠", "♥", "♦", "♣"]; +let rank = card.slice(0, -1)// This is extracting the bit before the suits alone +let suit = card.slice(-1) // THis is extracting the suit in the string + if(!ranks.includes(rank)){ + throw new Error("Invalid rank") + } + if (!suits.includes(suit)){ + throw new Error("Invalid suit") + } + if (rank === "A"){ + return 11} + if (["J", "K", "Q"].includes(rank)){ + return 10 + } + else{ + return Number(rank) + } } - // The line below allows us to load the getCardValue function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getCardValue; @@ -40,6 +71,20 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("5♣"), 5); +assertEquals(getCardValue("2♣"), 2); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("6♥"), 6); +assertEquals(getCardValue("5♥"), 5); +assertEquals(getCardValue("8♥"), 8); +assertEquals(getCardValue("4♥"), 4); +assertEquals(getCardValue("3♥"), 3); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("7♥"), 7); + // Handling invalid cards try { @@ -52,3 +97,23 @@ try { } // What other invalid card cases can you think of? + +try { + getCardValue("A"); + console.error("Error not thrown for missing suit"); +} catch (e) { + console.log("Error thrown for missing suit 🎉"); +} + +try { + getCardValue(""); + console.error("Error not thrown for empty string"); +} catch (e) { + console.log("Error thrown for empty string🎉"); +} +try { + getCardValue("Apple"); + console.error("Error not thrown"); +} catch { + console.log("Error thrown 🎉"); +} \ No newline at end of file From a8b6057a2ef01993e190b100ecbbfba17aa58785 Mon Sep 17 00:00:00 2001 From: Rizqah Date: Wed, 8 Jul 2026 10:13:06 +0100 Subject: [PATCH 6/9] jests test written for get angle type --- .../implement/1-get-angle-type.js | 13 ++++++-- .../1-get-angle-type.test.js | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 4e1bff06ae..bbf418a39b 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -31,6 +31,12 @@ function getAngleType(angle) { else if (angle > 180 && angle < 360){ return "Reflex angle"; } + else if(angle === 0){ + return "Zero Angle" + } + else if(angle === 360){ + return "Complete angle" + } else{ return "Invalid angle"; } @@ -71,10 +77,11 @@ assertEquals(getAngleType(181), "Reflex angle"); assertEquals(getAngleType(249), "Reflex angle"); // Test for invalid angles -assertEquals(getAngleType(0), "Invalid angle"); -assertEquals(getAngleType(361), "Invalid angle"); assertEquals(getAngleType(-980), "Invalid angle"); -assertEquals(getAngleType(90), "Right angle"); +assertEquals(getAngleType(9082), "Right angle"); assertEquals(getAngleType(672), "Invalid angle"); +// +assertEquals(getAngleType(0), "Zero angle"); +assertEquals(getAngleType(360), "Complete angle"); console.log("Execution finished! If any test failed, console.assert errors will appear above."); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..09db096eba 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -14,7 +14,38 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle") +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + expect(getAngleType(90.1)).toEqual("Obtuse angle"); + expect(getAngleType(179.9)).toEqual("Obtuse angle"); + expect(getAngleType(99.8)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when (angle === 180)`, () => { + expect(getAngleType(180)).toEqual("Straight angle") +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various Reflex angles, including boundary cases + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(256)).toEqual("Reflex angle"); + expect(getAngleType(359.9)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return "Invalid angle" when (angle > 360 || angle < 0)`, () => { + // Test various invalid angles + expect(getAngleType(-180)).toEqual("Invalid angle"); + expect(getAngleType(561)).toEqual("Invalid angle"); + expect(getAngleType(980)).toEqual("Invalid angle"); +}); +test(`should return "Zero angle" when (angle === 0)`, () => { + expect(getAngleType(0)).toEqual("Zero angle"); +}); +test(`should return "Zero angle" when (angle === 360)`, () => { + expect(getAngleType(360)).toEqual("Complete angle"); +}); + From d0fa6f8bf8cd8cdb7b9d96cb1bcc7fc9ca828f16 Mon Sep 17 00:00:00 2001 From: Rizqah Date: Fri, 10 Jul 2026 09:23:59 +0100 Subject: [PATCH 7/9] rewrite tests with jest --- .../implement/2-is-proper-fraction.js | 4 ++++ .../2-is-proper-fraction.test.js | 18 ++++++++++++++++ .../3-get-card-value.test.js | 21 +++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 77dc328283..d1a29bfc62 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -35,4 +35,8 @@ assertEquals(isProperFraction(1, 2), true); assertEquals(isProperFraction(93, 112), true); assertEquals(isProperFraction(2, 1), false); assertEquals(isProperFraction(80, 80), false); +assertEquals(isProperFraction(-10, -15), true); +assertEquals(isProperFraction(-35, 25), false); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 1), true); console.log("Execution finished! If any test failed, console.assert errors will appear above."); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba1..7178de0162 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// proper fractions +test(`should return true when denominator is higher than numerator`, () => { + expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(2, 7)).toEqual(true); + expect(isProperFraction(89, 101)).toEqual(true); +}); +// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs +test(`should return true when negative/positive numerator is less than the positive/negative denominator`, () => { + expect(isProperFraction(-20, -30)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(58, -68)).toEqual(true); +}); +// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs +test(`should return false when negative/positive numerator is greater than the positive/negative denominator`, () => { + expect(isProperFraction(-50, 10)).toEqual(false); + expect(isProperFraction(100, -2)).toEqual(false); + expect(isProperFraction(-1, -0)).toEqual(false); +}); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..99e0d0af4c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -3,12 +3,29 @@ const getCardValue = require("../implement/3-get-card-value"); // TODO: Write tests in Jest syntax to cover all possible outcomes. - +//["♠", "♥", "♦", "♣"]; // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); - +//Case 2: Face Cards(J, Q,K) +test(`Should return 10 when given a face card`, () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); + expect(getCardValue("J♦")).toEqual(10); +}); +//case 3: Number Cards (2-10) +test(`Should return the number when given a number card`, () => { + expect(getCardValue("4♠")).toEqual(4); + expect(getCardValue("9♣")).toEqual(9); + expect(getCardValue("2♦")).toEqual(2); +}); +//Case 4: Invalid cards +test(`Should return the invalid suit or invalid rank when given an invalid card`, () => { + expect(getCardValue("4🎉")).toEqual("Invalid suit"); + expect(getCardValue("20♣")).toEqual("Invalid rank"); + expect(getCardValue("Apple")).toEqual("Invalid card"); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) From 5343ebf9ac44f18cb144d49880906538ec615b86 Mon Sep 17 00:00:00 2001 From: Rizqah Date: Fri, 10 Jul 2026 20:31:19 +0100 Subject: [PATCH 8/9] rewrite tests with jests complete --- .../implement/1-get-angle-type.js | 4 ++-- .../implement/2-is-proper-fraction.js | 2 +- .../implement/3-get-card-value.js | 23 +++++++++---------- .../2-is-proper-fraction.test.js | 2 +- .../3-get-card-value.test.js | 10 ++++---- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index bbf418a39b..f5ecd6f87f 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -32,7 +32,7 @@ function getAngleType(angle) { return "Reflex angle"; } else if(angle === 0){ - return "Zero Angle" + return "Zero angle" } else if(angle === 360){ return "Complete angle" @@ -78,7 +78,7 @@ assertEquals(getAngleType(249), "Reflex angle"); // Test for invalid angles assertEquals(getAngleType(-980), "Invalid angle"); -assertEquals(getAngleType(9082), "Right angle"); +assertEquals(getAngleType(9082), "Invalid angle"); assertEquals(getAngleType(672), "Invalid angle"); // assertEquals(getAngleType(0), "Zero angle"); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index d1a29bfc62..a5f7be1dad 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,7 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - return numerator < denominator; + return Math.abs(numerator) < Math.abs(denominator); // TODO: Implement this function } diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index a65871f335..9fb41df7af 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -23,6 +23,9 @@ function getCardValue(card) { // TODO: Implement this function + if (typeof card !== "string" || card.length < 2 || card.length > 3) { + throw new Error("Invalid card"); + } const ranks = [ "A", "2", @@ -41,11 +44,12 @@ function getCardValue(card) { const suits = ["♠", "♥", "♦", "♣"]; let rank = card.slice(0, -1)// This is extracting the bit before the suits alone let suit = card.slice(-1) // THis is extracting the suit in the string + if(!ranks.includes(rank)){ - throw new Error("Invalid rank") + throw new Error("Invalid card") } if (!suits.includes(suit)){ - throw new Error("Invalid suit") + throw new Error("Invalid card") } if (rank === "A"){ return 11} @@ -55,6 +59,7 @@ let suit = card.slice(-1) // THis is extracting the suit in the string else{ return Number(rank) } + } // The line below allows us to load the getCardValue function into tests in other files. // This will be useful in the "rewrite tests with jest" step. @@ -100,20 +105,14 @@ try { try { getCardValue("A"); - console.error("Error not thrown for missing suit"); + console.error("Error not thrown for invalid card missing suit"); } catch (e) { - console.log("Error thrown for missing suit 🎉"); + console.log("Error thrown for invalid card missing suit🎉"); } try { getCardValue(""); - console.error("Error not thrown for empty string"); + console.error("Error not thrown for invalid card containing empty string"); } catch (e) { - console.log("Error thrown for empty string🎉"); -} -try { - getCardValue("Apple"); - console.error("Error not thrown"); -} catch { - console.log("Error thrown 🎉"); + console.log("Error thrown for invalid card containing empty string"); } \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7178de0162..b6a6101ead 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -23,6 +23,6 @@ test(`should return true when negative/positive numerator is less than the posit // Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs test(`should return false when negative/positive numerator is greater than the positive/negative denominator`, () => { expect(isProperFraction(-50, 10)).toEqual(false); - expect(isProperFraction(100, -2)).toEqual(false); + expect(isProperFraction(100, 2)).toEqual(false); expect(isProperFraction(-1, -0)).toEqual(false); }); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index 99e0d0af4c..516a6bb956 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -21,10 +21,10 @@ test(`Should return the number when given a number card`, () => { expect(getCardValue("2♦")).toEqual(2); }); //Case 4: Invalid cards -test(`Should return the invalid suit or invalid rank when given an invalid card`, () => { - expect(getCardValue("4🎉")).toEqual("Invalid suit"); - expect(getCardValue("20♣")).toEqual("Invalid rank"); - expect(getCardValue("Apple")).toEqual("Invalid card"); +test(`Should return the invalid suit, invalid card or invalid card`, () => { + expect(() => getCardValue("Apple")).toThrow("Invalid card"); + expect(() => getCardValue("4🎉")).toThrow("Invalid card"); + expect(() => getCardValue("20♣")).toThrow("Invalid card"); }); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) @@ -33,5 +33,5 @@ test(`Should return the invalid suit or invalid rank when given an invalid card` // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: -// https://jestjs.io/docs/expect#tothrowerror +// https://jestjs.io/docs/expecttothrowerror From 5c6de8ac1d62f865a1b57487dc479c207b878ba6 Mon Sep 17 00:00:00 2001 From: Rizqah Date: Fri, 10 Jul 2026 21:07:39 +0100 Subject: [PATCH 9/9] Remove Sprint 1 files from this PR --- Sprint-1/1-key-exercises/1-count.js | 2 -- Sprint-1/1-key-exercises/2-initials.js | 7 +++++-- Sprint-1/1-key-exercises/3-paths.js | 7 +++---- Sprint-1/1-key-exercises/4-random.js | 5 +---- Sprint-1/2-mandatory-errors/0.js | 4 ++-- Sprint-1/2-mandatory-errors/1.js | 3 +-- Sprint-1/2-mandatory-errors/2.js | 2 -- Sprint-1/2-mandatory-errors/3.js | 5 +++-- Sprint-1/2-mandatory-errors/4.js | 4 ++-- .../3-mandatory-interpret/1-percentage-change.js | 15 ++++----------- Sprint-1/3-mandatory-interpret/2-time-format.js | 11 +++++------ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 8 ++------ Sprint-1/4-stretch-explore/chrome.md | 4 ---- Sprint-1/4-stretch-explore/objects.md | 10 ++-------- 14 files changed, 30 insertions(+), 57 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 7601e82f47..117bcb2b6e 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,5 +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 -// In Line 3, count is a variable, and the = is an assignment operator that stores the result of the operation(Addition) -//Line 3 is incrementing the count variable by 1 \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 2c11be1be8..47561f6175 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -1,8 +1,11 @@ +let firstName = "Creola"; +let middleName = "Katherine"; +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 = ``; -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 + diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 24597e36c2..ab90ebb28e 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,8 +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.slice(0, filePath.lastIndexOf("/")); -const ext =filePath.slice(filePath.indexOf(".")+1); -console.log(dir) -console.log(ext) +const dir = ; +const 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 bc9c3fe543..292f83aabb 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,12 +1,9 @@ const minimum = 1; const maximum = 100; + const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -console.log(num) // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing -//The math.Floor method rounds a number to the nearest integer, so using bodmas, -//the expressions are evaluated, the minimum which equals 1 is added to 1 then subtracted from maximum(100), after which it is multiplied by -//a random number between 0-1 exclusive and then rounded down to the nearest integer after which the minimum is added. The values of num produced ranges from 1-100 \ 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 65ad3030d6..cf6c5039f7 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 diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 0ba75ba699..7a43cbea76 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,5 +1,4 @@ // trying to create an age variable and then reassign the value by 1 const age = 33; -let age = 33; -age = age + 1; \ No newline at end of file +age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 789b28d090..e09b89831d 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,6 +2,4 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); -// what's the error ? You cannot access a variable before initialization. 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 5004790192..ec101884db 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,8 +1,9 @@ const cardNumber = 4533787178994213; -const last4Digits = String(cardNumber).slice(-4); +const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber +// However, the code isn't working +// 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 expression last4Digits is assigned to, in order to get the correct value -//It didn't work because the method only works for strings so to make it work the card number should be saved as a string. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index b0feba1bbc..5f86c730bc 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const twelveHourClockTime = "8:53pm"; -const twentyFourHourClockTime = "20:53"; +const 12HourClockTime = "8:53pm"; +const 24hourClockTime = "20:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 7cd56ef8a8..e24ecb8e18 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,28 +2,21 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); -carPrice = Number(carPrice.replaceAll(",","")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; + console.log(`The percentage change is ${percentageChange}`); + // 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 -//The function call are made five times -//line 4, 5, 10 - // 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? -// Line 5, A comma was missing between the arguments. Include a comma between the arguments to fix the error. - // c) Identify all the lines that are variable reassignment statements -//Lines 7 & 8 // d) Identify all the lines that are variable declarations -//Lines 1 & 2 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -//This expression replaces every instance of "," with "". \ 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 e7125bcf5f..47d2395587 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -9,18 +9,17 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; console.log(result); +// For the piece of code above, read the code and then answer the following questions + // a) How many variable declarations are there in this program? -//6 + // b) How many function calls are there? -//1 -// c) Using documentation, explain what the expression movieLength % 60 represents it represents the remainder when movielength is divided by 60 + +// c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -//The expression assigned to totalMinutes means that the remaining seconds are subtracted from the movieLength and then divided by 60 to get the total number of minutes in the movie length. // e) What do you think the variable result represents? Can you think of a better name for this variable? -//The variable result represents the total time of the movie, in hours minutes and seconds. A better name for this variable could be totalTimeStr // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -//Yes it would work, we have accommodated for all length \ 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 f935d926dd..60c9ace69a 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,23 +1,19 @@ const penceString = "399p"; -//initializes a string variable with the value "399p" const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); -//initializes a string variable by taking a substring of penceString up until the part where the p is, so without the p + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -//it initializes a string variable by padding the start of the pencestringwithoutrailing with 0 if the length is less than 3 const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); -//it initializes a string variable by taking all the strings except from the last two letters const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); - //initializes a string variable by taking a substring from paddedpencenumberstring except from the last two letters and padding the end wih 0, if it is less than 2 console.log(`£${pounds}.${pence}`); @@ -28,4 +24,4 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initializes a string variable with the value "399p" \ No newline at end of file +// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index ab27b76eb2..e7dd5feafe 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -12,11 +12,7 @@ invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? -A pop up notification saying 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? -It brings up a input tab to enter an answer What is the return value of `prompt`? -the input entered and sent by pressing ok, else it would return null - diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 1f278bc989..0216dee56a 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -1,22 +1,16 @@ ## Objects +In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. + Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? -undefined/ f log() native code Now enter just `console` in the Console, what output do you get back? -a list of all console types and how to use them Try also entering `typeof console` -object Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? -What does `console` store? The console object provides access to the debugging console. It stores text and data explicitly sent to it using methods like console.log() or console.info() -What does the syntax `console.log` or `console.assert` mean? -The assert() method writes a message to the console if an expression evaluates to false. The log() method writes (logs) a message to the console. -In particular, what does the `.` mean? -This is a Dot Notation, it is used to access an object's properties or methods