From 8fd0ef3722f439bbf8d01786216cb00b934f3e32 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Sat, 7 Mar 2026 13:50:33 +0000 Subject: [PATCH] fixed sprint-1 pull request issue --- Sprint-1/1-key-exercises/1-count.js | 1 + Sprint-1/1-key-exercises/2-initials.js | 5 ++--- Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- Sprint-1/1-key-exercises/4-random.js | 9 +++++++++ Sprint-1/2-mandatory-errors/0.js | 4 ++-- Sprint-1/2-mandatory-errors/1.js | 2 +- Sprint-1/2-mandatory-errors/2.js | 4 ++++ Sprint-1/2-mandatory-errors/3.js | 12 +++++++++++- Sprint-1/2-mandatory-errors/4.js | 4 ++-- .../3-mandatory-interpret/1-percentage-change.js | 14 ++++++++++++-- Sprint-1/3-mandatory-interpret/2-time-format.js | 13 +++++++++++-- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 8 ++++++++ Sprint-1/4-stretch-explore/chrome.md | 9 ++++++++- Sprint-1/4-stretch-explore/objects.md | 11 +++++++++++ 14 files changed, 87 insertions(+), 16 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..78cd5bd9a 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 1 is increasing the count, it is called increment in programming diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..e1f282543 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,6 @@ 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[0]}${middleName[0]}${lastName[0]}`; +console.log(initials); //CJK // 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..d5e7d226c 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 lastDotIndex = filePath.lastIndexOf("."); +const dir = filePath.slice(0, lastSlashIndex); +const ext = filePath.slice(lastDotIndex + 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 292f83aab..71774ac5f 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,12 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +//In the above expression num represent a variable that will store the result of that will be obtained from from the expression. +// maximum and minimum are variables available on the global scope, as inputs. +// They are evaluated first because of the parenthesis, this gives the precedence +// The output from the parenthesis is now going to serve as the range for the Math.random() method. +// Math.random() method produce random values from 0-1, with 0 and 1 inclusive and exclusive respectively +// The range value makes Math.random() to return result from 0 to range-1 +// the Math.floor() methods rounds down the value to the nearest whole number. +// The result from th random operation is added back to the minimum value to return num. diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..65ad3030d 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..34718e067 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,9 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +// JavaScript is single-threaded because it executes tasks in a single flow using a call stack. The function was called before it was declared, +// It was also declared with const, which can not be hoisted to the top, like var. +// this result to undefined. console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..9acf5e997 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,5 @@ -const cardNumber = 4533787178994213; +let cardNumber = 4533787178994213; +cardNumber = cardNumber.toString(); const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +8,12 @@ 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 + +// The last4Digits variable should store the last 4 digits of cardNumber +// 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 + +// The variable cardNumber is a number data type, numbers do not have slice methods or function, only string does. +//TypeError: cardNumber.slice is not a function +// Yes, it gives what i predicted diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..e48324f14 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..540730c7d 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(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -13,10 +13,20 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made -// 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? +//There are 5 function call in this code. +// 1. Line 4 has 2 function call, .replaceAll() and Number() +//2. Line 5 ditto line 4 +// 3. line 10 console.log() that logs the result to the console +// 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? +// The error in this code is coming from line 5. The wrong use of the replaceAll syntax without a separator in the function arguments. +// I will fix this problem by reading the documentation, to see the right way the syntax should be written. +//Then i will add the comma where necessary // c) Identify all the lines that are variable reassignment statements + // line 4 and 5 are variable reassignment // d) Identify all the lines that are variable declarations + // line 1,2,7,8 are all variable declaration // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// this expression replaces the comma at the string with an empty string and the convert the string data type to a number data type \ 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..408c0887e 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -10,16 +10,25 @@ 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? +// there are 6 variable declaration. + // b) How many function calls are there? +// One function call // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// The % operator checks the remainder of that expression when being evaluated. It is similar to the remainder theorem in mathematics. +// if it returns 0, even, if it returns value other than zero, it odd. it is mostly used for checks in programming // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The total time for this movie is 8760 second and fractional 24 seconds, line 4 is used to deduct the fractional 24 seconds +// Then convert the whole number seconds to minute. // e) What do you think the variable result represents? Can you think of a better name for this variable? - +// the variable result represent total movie duration in hours,minute and seconds. +// const=runningTime // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// this code works for all movie running time and integer values. +// for movie running time which are multiples of 60 it returns hours with 0 minutes and 0 seconds \ 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..3ea992963 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,11 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);: used to strip off the last substring character 'p' +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): Used to add '0' to the start of the string if the string +// length is less than 3, else if string length is 3 it does not pad. +// 4.const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);: This expression copy the first character +// from every length character of the padded string +// 5.const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0");: This expression add '0' to the end if the paddedString is not +// upto 2 characters +// // 6. this line is a function call to log the argument inside it to the console. it use template literals to get the values of the variables diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..9aa787127 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -6,13 +6,20 @@ Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/ Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. Let's try an example. - In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; +It invokes the modal window and display Hello world + What effect does calling the `alert` function have? +It freezes the window till i click Ok before ii can make use of my computer 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`. +const myName=prompt(`"What is your name?"`) +return value myName=Edak What effect does calling the `prompt` function have? +it invokes a modal window, and allows me to enter an input value What is the return value of `prompt`? +it returns the value i entered "Edak" +if "Edak" is entered an cancelled it returns null \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..747a85829 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,23 @@ 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? +I get `f log(){[native code]}` in return Now enter just `console` in the Console, what output do you get back? +I get`console{debug: f,error:f,info:f,log:f....}` Try also entering `typeof console` +I get `object` Answer the following questions: What does `console` store? +The console store methods for debugging the console such as assert. clear,count,countReset,debug etc + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +console.log: Output a message to the console + +console.assert: Log an error message to the console if the first argument is false. +`.` This is a member access operator used to access methods and properties of objects +console store methods and functions