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..5319d5d12 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,10 +1,9 @@ const firstName = "Creola"; const middleName = "Katherine"; const 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. -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..d530e2731 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,13 @@ 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. +//'math.floor'Round down suppose 14.4 going to 14 as well as 14.9 also down to 14 to the nearest whole number (integer). +// i think Changes the whole range to be greater by the minimum value +//Ensures the value never comes less than 1. +//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). +// const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;. This step helps to generate the random number and helps to change the decimal number. +console . log (num) +// \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..c15168475 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..875eee972 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,11 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +console.log(age); + +/* In this case age is not const means variable is not reassigned so that, +/*we throws a TypeError: Assignment to constant variable*/ + //I try by let where console.log(age) shows Running] node "c:\Users\Desktop\code your future\Module-Onboarding\Module-JavaScript-Fundamentals\Sprint-2\Sprint-2\2-mandatory-errors\1.js" +//34. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..d45824531 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,8 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? - -console.log(`I was born in ${cityOfBirth}`); +// It's shows the reference error because variables should be declared first then the console.log(). +// console.log(`I was born in ${cityOfBirth}`); +// const cityOfBirth = "Bolton"; +/*we need to put declare variables(const cityOfBirth = "Bolton";) in first line in second line we use used console.log to print the output*/ const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ 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..f076874a2 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,14 @@ 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 // 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? +// 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 +// Small s string is not function defined so that it showed the type ReferenceError. +//When i put actual capital S String function defined and print the result(output). \ 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..43a8f654c 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const HourClockTime12 = "8:53pm"; +const hourClockTime24 = "20:53"; + + +/*variable is not start with number show syntaxerror.*/ +// i just move the number at the end. \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..d1e742e1a 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..a50ec864d 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,5 +1,8 @@ -const movieLength = 8784; // length of movie in seconds - +const movieLength = 8784; +// const movieLength = -1; +// const movieLength = 8784.5; +// const movieLength = 'abc'; +// const movieLength = 3605; const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +15,31 @@ 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. movieLength % 60 represent that when movieLength is divided by 60 it return the remainder. +It's mainly represent the remainingSeconds.*/ // 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 formatted 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 +/* No, it's does not work for all values. It works correctly for any non-negative whole number of seconds. +1. Negative Number: -1 gives the answer 0:0:-1 which is not the valid time because -1 is not the time formate. +due to the divide the dividend keeps the negatives seconds. +2. Decimals: Move length: 8784.5 gives the answer 2:26:24.5. So, seconds are not a whole numbers in real world. +3. Not a numbers: move length: 'abc'.. When we put the not numbers then they gives the NaN:NaN:NaN(Not a Number) answer. +4. also when we divide the numbers like 3605 its shows the answer 1:0:5 but it needs to shows 1:00:05. Its the problem of formating. +Values that divide by 60 with no remainder (like 120) also work; they just give 0 seconds (0:2:0). +for normal values like 8784 it's shows the correct answer. Its work normally for normal values but shows Nan and formating error for others values. */ \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..9328ba9b4 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -4,18 +4,25 @@ const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); - +// remove the p from the "399p" and make "399" const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// padStart(3, "0") adds "0" at the start until the string is 3 characters long +//Because we have to convert pound and pence. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +// In this we store the first index number into pound and remaining other should be removed. for example, 399 we stored the 3 into Pounds variables and remaining 99 should be removed because the substring start from 0 index to length-2. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); + // At last we get the last two characters as the pence and first one or index 0 is removed . + // In this, padEnd add extra until its reach to target. In this its add 2 character . + 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 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.