From bd936fc8cb9e6bdcc74d8238384260da85a53621 Mon Sep 17 00:00:00 2001 From: gaireprakash20-ops Date: Tue, 22 Sep 2026 15:36:01 +0100 Subject: [PATCH 1/4] Key excercises for sprint 2 --- Sprint-2/1-key-exercises/1-count.js | 3 ++- Sprint-2/1-key-exercises/2-initials.js | 8 ++++---- Sprint-2/1-key-exercises/3-paths.js | 8 +++++--- Sprint-2/1-key-exercises/4-random.js | 7 +++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..eeb9e9673 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -3,4 +3,5 @@ let count = 0; 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 +// Describe what line 3 is doing, in particular focus on what = reassign a variable using the = + operator. +//Line 1 assigns count = 0. Line 3 uses that value (0) and adds 1, so count becomes 1. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..e9fc80867 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,10 +1,10 @@ const firstName = "Creola"; const middleName = "Katherine"; const lastName = "Johnson"; - +const CKJ = "something" // 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. -const initials = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn +const 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-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..575259d63 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,9 @@ 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, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".")); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..6e63bb1e5 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,10 @@ 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 this exercise, num represent the value integer number between 1 to 100. +//Math.random generates a random decimal number from 0 up to 1, but not including, 1. +// down to the nearest whole number (integer). +//Running the program several times generate the whole number(integer) like (1,10,15,44,66,55) several times between 1 to 100 all 100 number has a equal 1% chance to appear(generate). +console . log (num) +// \ No newline at end of file From 7b9e573edc037f3432618400b815d8bd82cab6cd Mon Sep 17 00:00:00 2001 From: gaireprakash20-ops Date: Tue, 22 Sep 2026 15:38:52 +0100 Subject: [PATCH 2/4] second commit for sprint change --- Sprint-2/2-mandatory-errors/0.js | 5 +++-- Sprint-2/2-mandatory-errors/1.js | 3 +++ Sprint-2/2-mandatory-errors/2.js | 3 +++ Sprint-2/2-mandatory-errors/3.js | 5 ++++- Sprint-2/2-mandatory-errors/4.js | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..d48de18d1 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ -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? +for single line we used // and for multiple line use /* \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..0aadb7463 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,6 @@ const age = 33; age = age + 1; + +/* In this case age is not const means variable is not reassigned so that, + we throws a TypeError: Assignment to constant variable.2 diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..43d5d8516 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,6 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + + +/*we need to put declare variables(const cityOfBirth = "Bolton";) in first line after using expression console.log. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..e64eb5c66 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = string(cardNumber).slice(-4); +console.log (last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +8,5 @@ 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 +//Card number is a number not a string so it will throw typeerror. +// i did not think slice method can not run in number method so that i change it in string \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..67705bc68 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,3 @@ const 12HourClockTime = "8:53pm"; const 24hourClockTime = "20:53"; +/*variable is not start with number show syntaxerror. From 878dae9dd897077c246a922f06cea29b80ec6a6b Mon Sep 17 00:00:00 2001 From: gaireprakash20-ops Date: Tue, 22 Sep 2026 15:40:14 +0100 Subject: [PATCH 3/4] first formula related file in javascript --- .../1-percentage-change.js | 31 +++++++++++++------ .../3-mandatory-interpret/2-time-format.js | 13 ++++++-- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 7 ++++- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..458fa6d7f 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/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; @@ -12,11 +12,24 @@ 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 - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +/* there has five function in line 4 and and console . log also has one +line 4 and 5 has two Number() function +line 4 and 5 has two replaceALL() function +line 10 has one console . log () + +/* b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? + In line five error shown in replaceAll("," "")); missing comma before last two comma(",",""). + +/* c) Identify all the lines that are variable reassignment statements +line 4 carPrice = Number(carPrice.replaceAll(",", "")); +line 5 priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +As per the carPrice and priceAfterOneYear has been declared in line 1 and 2 by using let variable. + +/*d) Identify all the lines that are variable declarations +line 1 let carPrice = "10,000"; +line 2 let priceAfterOneYear = "8,543"; +line 7 const priceDifference = carPrice - priceAfterOneYear; +line 8 const percentageChange = (priceDifference / carPrice) * 100; + +/* e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +replaceALL throwout all the commas from the string and number became numerical value. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..72f0689d4 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,5 +1,4 @@ -const movieLength = 8784; // length of movie in seconds - +const movieLength = 8784; const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -8,18 +7,28 @@ 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? +/* line 1 const movieLength line 3 const remainingSeconds line 4 const totalMinutes + line 6 const remainingMinutes line 7 const totalHours line 9 const result // b) How many function calls are there? +/* there are one function + console.log(result); // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +/*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? +/* This expression convert movies time second into minutes dividend by 60 second. // e) What do you think the variable result represents? Can you think of a better name for this variable? +/* The variable represent the movieLength in second,minutes and hours. + We can change this name as movieTime. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +/* In this section we can only use the positive natural numbers but if we put numbers that divide by 60 without a remainder get the exact time like 10, 20 50. diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..59d3eb0f1 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -4,18 +4,23 @@ const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); - +// remove the p from the "399p" and make "399" const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//padStart() add characters to the starting of the string and provide 3 long characters. +//Because we have to convert pound and pence. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +// we take out the 2 character and store the remaining part of the string as the pound. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); + // At last we get the last two characters as the pence. console.log(`£${pounds}.${pence}`); +//We can display the price of pound and pence like £3.99. // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds From 982244fc3116d9ab5644d4394e4b1d8139aeed2f Mon Sep 17 00:00:00 2001 From: gaireprakash20-ops Date: Tue, 22 Sep 2026 15:40:52 +0100 Subject: [PATCH 4/4] chrome and objects commit --- Sprint-2/4-stretch-explore/chrome.md | 4 ++++ Sprint-2/4-stretch-explore/objects.md | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..27494e68a 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -8,8 +8,12 @@ Let's try an example. In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; What effect does calling the `alert` function have? +Answer An alert popped up 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? +Answer A popup prompts me to write my name. + What is the return value of `prompt`? +Answer The value i entered in the text box. diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..ccad49517 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -5,12 +5,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? +Answer The output is ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? +Answer console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, ...} but i can't copy it. + Try also entering `typeof console` +Answer It shows object' Answer the following questions: What does `console` store? +console is an object with properties that are function values. These functions are called methods because they belong to the console object. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +console.log means "access the log method from the console object" and console.assert means "access the assert method from the console object.