diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..95ada8c65d 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +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 + +// Line 3 increases the number by one and reassigns the new value to count, which stored 0 . diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..278e0b25d5 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -7,5 +7,8 @@ let lastName = "Johnson"; let initials = ``; -// https://www.google.com/search?q=get+first+character+of+string+mdn +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..aa9cc25ff4 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -12,12 +12,15 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); +// 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 + 1); +const ext = filePath.slice(filePath.lastIndexOf(".")); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// console.log(ext); + +// https://www.google.com/search?q=slice+mdn +// console.log(dir); diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..141db25433 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,11 @@ 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 + +// console.log(num); + +// 1) Num represent a randomly generated whole number between maximum and minimum // + +// 2) Firstly, Math.random create a random number between 0 to 1 then using a maximum and minimum,which gives us range. +// Multiplying them create a random number inside that range. Math.floor remove decimal parts and give us whole number +// finally we add minimum number ( + minimum),which start from a minimum value. Therefore num represent a whole number. diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..cc9e5d1180 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ 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 +We don't want the computer to run these 2 lines - how can we solve this problem? + +// We comment them using slash(//) where human can read and computer can't read because it is not a code or translated into code// \ 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..97f69fcd5e 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; +let age = 33; age = age + 1; +// console.log(age); diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..1b21eba76e 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // 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}`); 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 ec101884db..4528c92323 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,7 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +let cardNumber = 4533787178994213; +const ToString = cardNumber.toString(); +let last4Digits = ToString.slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..8c150d752a 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,3 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const HourClockTime = "8:53pm"; +const hourClockTime = "20:53"; +// console.log(HourClockTime); diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..0fecd55c94 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; @@ -20,3 +20,9 @@ console.log(`The percentage change is ${percentageChange}`); // 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? + +// 1) five function call there including log function .Lines 4 has two function and lines 5 has two function . +// 2 ) problem was line number 5 where comma was missing. +// 3) reassignment statement lines are 4 and 5. +// 4) declaration lines are 1,2,7 and 8 +// 5) line number 4, first it is removing commas using replaceAll then converting string to number for calculation. diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..6108f20009 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,5 +1,5 @@ const movieLength = 8784; // length of movie in seconds - +// 9237, 8784, -5897... const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -23,3 +23,10 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// a) there are 6 variable declaration. +// b) there is zero function call . (only one is console.log but it is not part code execution) +// c)represents the number of seconds left over after converting the movie length into whole minutes. +// d) It calculates how many whole minutes are in the movie after taking away extra second that don't make full minutes. +// e) it represents time format like hours : minutes: second and I think MovieLengthDuration or short MovieDuration +// I think all value will work except negative value because negative value gives negative outcome. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..89b8ab03eb 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,10 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// line 1 creating a string containing price in pence and this is starting value that programme will convert into pound. +// line 3 removing p from the end of 399p because p is not needed when converting into pound or pence. +// line 8 making sure string has at least 3 digit by adding zero if needed and this makes easier to separate pound and pence consistently. +// line 9 extract everything except last two digit . +// line 14 extract last two digit and padEnd() ensures the pence part always has 2 digits. +// line 18 to print value for checking . diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..0c280e9889 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -12,7 +12,11 @@ invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +1. alert function display a pop-up message box in the browser containing text "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? What is the return value of `prompt`? + +2. calling a prompt display a pop-up message box and ask for user input and prompt return a text entered by user as string. diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..31fb74f38a 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -6,11 +6,18 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +answer: it shows only log function itself. + Now enter just `console` in the Console, what output do you get back? +answer: the output is console object .it shows available function/ method inside console object. Try also entering `typeof console` +Answer: this shows that console is object. Answer the following questions: What does `console` store? +answer: this one store an object that contain method used to interact with browser developer console. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +Answer : this one let us access to log function that store console object. `.` this one is a dot operator used to access something inside object . console.assert means accessing the assert method from the console object.