diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..9818641e3 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 +// Answer: "count + 1" is a value being assigned to the variable count and "=" is the assignement operator used to assign values to a variable \ 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..210b27189 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,9 @@ 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..9bce50b9b 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -10,14 +10,30 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; + +// Find the last slash and we can seperate the base from "dir" const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); -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 +// Find the last dot +const lastDot = base.lastIndexOf("."); +// console.log(`The base part of ${filePath} is ${base}`); + +// Ectract everything before the base +const dir = filePath.slice(0, lastSlashIndex); +// Extract the txt extention from the dot +const ext = base.slice(lastDot); + + + -const dir = ; -const ext = ; -// https://www.google.com/search?q=slice+mdn \ No newline at end of file + + + + + +// Create a variable to store the dir part of the filePath variable +// Create a variable to store the ext part of the variable +console.log(`The base part of ${filePath} is ${base}`); +// Moved to bottom its confusing me \ 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..45e088a15 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 + +// Answer: Inermost brackets first (maximum - minimum + 1) this is calcuating the range +// Math.random generated a number between 0 and 1 but wont get to 1 +// Math.random * 100 moved the comma by 2 decimal places +// Math.floor wii remove decimal parts of the number +// + minimum will add 1 + +console.log(num); \ 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..b9cee32a6 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,8 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +age = 1; + + +// Will remove the constant varible and use the let keyword \ 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..b396d371e 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/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}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + +// The variable was at the bottom so we could not access it, so it has to be hoisted at the top \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..c0e648d9f 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,18 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// 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 +// Answer: Missing console.log // Then run the code and see what error it gives. +// Error:we had TypeError: cardNumber.slice is not a function // Consider: Why does it give this error? Is this what I predicted? If not, what's different? +// "cardNumber.slice" must declared as a function, this is not what i thought, the difference is that the code is incomplete and so will add a function // Then try updating the expression last4Digits is assigned to, in order to get the correct value + + +// After some research i found out that ".slice()" only works on strings so we have to convert the numbers into a string first +// Also learned abour method chaining \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..35107affb 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime12 = "20:53"; +const hourClockTime24 = "08:53"; + +// You cannot name a variable starting witha number \ 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..fb9379720 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; @@ -12,11 +12,16 @@ 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 + // Anwer: The function is called 4 times in the code line 7 and 8 then we have the built-in functions line 4 and 5 // 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? + // Answer: The error is coming from line 5 a comma is missing between the quotes '(priceAfterOneYear.replaceAll("," ""))' // c) Identify all the lines that are variable reassignment statements + // Answer: Line 4 and 5 // d) Identify all the lines that are variable declarations + // Answer: Line 1, 2, 7 and 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + // Answer: It removing all the commas and also converting the values to a number diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..9be358d74 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 81034; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,20 @@ 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? + // Answer: There are 6 // b) How many function calls are there? + // Answer: There ise one "Console.log" // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators + // Answer: This devides values and gives us the remainder // d) Interpret line 4, what does the expression assigned to totalMinutes mean? + // Answer: It subtracts remaining seconds from movie length then devides that by 60 // e) What do you think the variable result represents? Can you think of a better name for this variable? + // Answer: This will display the movie length formatted in hours, minutes and seconds, it can be named totalTime // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + // Answer: Yes it works with all values, this can be because there are template litterals in the result variable \ 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..092fde4ac 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,16 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// 2. penceStringWithoutTrailingP the last "p" from line 1 is removed + // substring() method will select a charactor from index 0 to -1, and return the new string "-1 is the last charactor" then we get "399" + +// 3. paddedPenceNumberString this is assingned to the variable penceStringWithoutTrailingP where a charactor is added to the beggining of the string by the method padStart + // 3 will add 2 zeros to the begining of the string, we have padStart(3, "0") and we already have three charactor + // if it was padStart(4, "0") then the result was "0399" + +// 4. pounds will take the paddedPenceNumberString, select all the charactors exept the last two + +// 5. pence selects the values in paddedPenceNumberString, then makes sure we have the last we have two digits at the end + +// console will print the output value in pounds \ No newline at end of file diff --git a/Sprint-1/Module-Structuring-and-Testing-Data b/Sprint-1/Module-Structuring-and-Testing-Data new file mode 160000 index 000000000..9b108f242 --- /dev/null +++ b/Sprint-1/Module-Structuring-and-Testing-Data @@ -0,0 +1 @@ +Subproject commit 9b108f242a001dd0ad82f7d4c96bb142b00d35c2 diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..b27020093 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,4 +1,6 @@ function repeat() { + const countString = [0]; + for(i ) return "hellohellohello"; }