diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..2f4204f4a 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,6 +1,7 @@ let count = 0; -count = count + 1; +count = count + 1; // Further note based on feedback => I can also describe this as 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 three adds 1 to the value of count and stores it as count \ 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 47561f617..1f5c553b3 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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 ab90ebb28..cb0633482 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -16,8 +16,16 @@ 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); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// Extract the file extension part +const lastDotIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDotIndex); + +console.log(`The directory part of ${filePath} is ${dir}`); +console.log(`The extension part of ${filePath} is ${ext}`); + +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..0fff4d2df 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,15 @@ 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 +// Math.floor() method always rounds down and returns the largest integer less than or equal to a given number +// Math.random() method returns a floating-point pseudo-random number in the range 0 to less than 1 +// Further information based on review: +// what is the use of (maximum-minimum+1) at line 4 => This is to ensure that we get a range of value between maximum and minimum +// what is the use of + minimum at line 4 => To make sure we do not get a number below the minimum +// what is the possible range of value of num => num 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 cf6c5039f..547d72389 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? I have added stroke to comment it out. \ 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..53e429469 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 = 34; age = age + 1; +console.log(age); \ 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 e09b89831..fcc425d94 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // 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}`); +// what's the error ? const cityofBirth needs to be declared before it can be used. 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..796ed943b 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,11 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +//const last4Digits = cardNumber.slice(-4); +const last4Digits=cardNumber.toString().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? +// Before running the code, make and explain a prediction about why the code won't work- This is because .slice is a string method. +// Then run the code and see what error it gives-It says cardNumber.slice is not a function. +// Consider: Why does it give this error? Is this what I predicted? If not, what's different? Like I mentioned .slice is string method. // 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 21dad8c5d..8222fe007 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; // This should be correctly written as "08:53 PM" in the 24 hour format + +// Further information based on review: +// line 1 should be written as const twelveHourClockTime = "20:53", +// line 2 should be written as const twentyFourHourClockTime = "08:53" +// \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..1ed150102 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,21 +2,21 @@ 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; console.log(`The percentage change is ${percentageChange}`); -// Read the code and then answer the questions below +// 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 +// a) How many function calls are there in this file? Write down all the lines where a function call is made: Thete are 5 functions- 2 on line 4, 2 on line 5 and 1 on line 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? +// 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 is needed -// c) Identify all the lines that are variable reassignment statements +// c) Identify all the lines that are variable reassignment statements- line 4 and line 5 -// d) Identify all the lines that are variable declarations +// d) Identify all the lines that are variable declarations: Line 1, Line 2, Line 7 and Line 8 -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - What is the purpose of this expression? This expression removed the comma in the number and convert the string into a number \ 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..83be0646e 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,5 @@ const movieLength = 8784; // length of movie in seconds +//const movieLength = 100; const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -11,15 +12,21 @@ 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? +// a) How many variable declarations are there in this program? 6 -// b) How many function calls are there? +// b) How many function calls are there? 1 // c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is the module operator, which calculated the remainder of the division of movieLength by 60 +// Further information based on feedback: This expresss represents the seconds left over when all the full minutes of the movie has been subtracted from total time. -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// d) Interpret line 4, what does the expression assigned to totalMinutes mean? Computes the the difference between movielength and remaining minutes. And divides this by 60. -// e) What do you think the variable result represents? Can you think of a better name for this variable? +// e) What do you think the variable result represents? Can you think of a better name for this variable? It gives the time of the movie in hours, minutes and seconds +// Further Information based on feedback => variable counld be moviedurationHMS -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer. It does work for all number inputs. +// f) For example, movieLength of 100 gives 0:-1:-40 and movieLength of 8784 gives 2:26:24 + +//Further information based on feedback: This is a mistake, it should be 0:1:40 \ 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..9977a3829 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,8 @@ 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); Removes the p from the string. Result=399 +// 3 const paddedPenceNumberString=penceStringWithoutTrailingP.padStart(3,"0"):This ensures that the pence value has at least three digits. It can add three leading zeros if necessary +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length-2); Extracts the pound part of rhe value. +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length-2).padEnd(2,"0"); Extracts the pence portion of the value +// 6. Computes out the final number in pounds and pence. diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..18f62c11c 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -8,11 +8,14 @@ Just like the Node REPL, you can input JavaScript code into the Console tab and Let's try an example. In the Chrome console, -invoke the function `alert` with an input string of `"Hello world!"`; +invoke the function `alert` with an input string of `"Hello world!"`; -What effect does calling the `alert` function have? +What effect does calling the `alert` function have? This prints Hello world to the console: The browser displays "Hello world!" in a pop up window Correction: it displays "Hello world!" in a pop up window. Not to the console. 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`? +What effect does calling the `prompt` function have? It displays a dialog box that allows the user to give an input +What is the return value of `prompt`? It displays a dialog box. +Correction: prompt returns the string input typed in by the User. +If the user clicks okay, it returns the string typed in by the user. +If the user clicks Cancel, the return value in null. diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..97374a21c 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -4,13 +4,16 @@ 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? +What output do you get? f log(){[native code]} -Now enter just `console` in the Console, what output do you get back? +Now enter just `console` in the Console, what output do you get back? console {debug: f, error: f, info: f,f log:f warn f,....} -Try also entering `typeof console` +Try also entering `typeof console` This gives 'object' Answer the following questions: -What does `console` store? +What does `console` store? It is used for logging information. It has its own methods that help to log information. It also help to debuggi What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +console.log outputs a message to the console. +If the assertion is false, it logs an error message to the console. + \ No newline at end of file