diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..6cadfef2b 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/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 + +// count is being increased each time the code runs by +1. = is basically just reassigning the value each time. diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..45eef73ed 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,12 @@ 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 = ``; +const firstChar = firstName.charAt(0); +const secondChar = middleName.charAt(0); +const thirdChar = lastName.charAt(0); + + +const initials = `${firstChar}${secondChar}${thirdChar}`; +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..e8e39ca58 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,11 @@ 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(base, -9); +const ext = filePath.slice(-4); + +console.log(ext) // https://www.google.com/search?q=slice+mdn \ 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..76182687f 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/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 + +// Math.floor() - rounds down to nearest integer +// Math.random() - gives a random number +// (max - min + 1) - 100 +// simple bodmas bro + +// math.random = 2 +// num = 201 \ 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..a76715850 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/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 +// 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? + +// Comment out lines with "//" \ 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..e03657d95 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/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; +// changed const to let \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..7f3af0111 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,7 @@ // 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}`); + +// You must first assign the var before u try to print it \ 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..8173975fa 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +7,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 +console.log(last4Digits) +// cardNumber was stored as a number, which does not work with .splice(). \ 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..0d4f38e63 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"; +const twelveHourClockTime = "8:53pm"; +const miliataryhourClockTime = "20:53"; +// variables cannot start with a number. \ 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..9ba2eae2d 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -1,7 +1,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; -carPrice = Number(carPrice.replaceAll(",", "")); +carPrice = Number(carPrice.replaceAll("," "")); priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); const priceDifference = carPrice - priceAfterOneYear; @@ -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 +// Number() line 4,5. .replaceAll() line 4,5. console.log() 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? +// line 5: put a comma between the find and replace // c) Identify all the lines that are variable reassignment statements +// line 4, 5. // d) Identify all the lines that are variable declarations +// line 1,2,7,8. // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// convert str to number type and find and replace commas with nothing so that the number is read correctly. \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..b9752191a 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 2; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,23 @@ 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? +// 6 // 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 +// its a rem calculation, basically taking how many groups of 60 are in the movie, and giving back the remainder. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// (movieLength - remainingSeconds): gives us a value that's an exact multiple of 60, so it divides evenly. +// / 60: takes the whole number and converts it to minutes // e) What do you think the variable result represents? Can you think of a better name for this variable? +// the movie length in hours, minutes and seconds. formattedDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// edge cases: negative movie length. For negative movie lengths it should print an error saying that movielength cannot be less than 0. +// : decimal numbers +// : should tell user that the unit is seconds diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..0435be1ff 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/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" +// 2. const penceStringWithoutTrailingP: from index 0, to length of string - 1 (4-1=3). (0,3) we get the string from index 0 to index 2 which removes the p at the end. +// 3. const paddedPenceNumberString: if length < 3, pad start of string with "0". since it is we just get 399. +// 4. const pounds: take string from index 0 to length of string - 2 (3-2=1). (0,1) we get the 1st index "3". +// 5. .substring(): length = 3. (3-2=1). (1,end of string). this gives us 99 +// 6. .padEnd(): if previous length of string < 2: pad end with "0" +// 7. console.log() basically just prints pounds and pence as the proper format (£"pound"."pence") using string literals +// NB: padding is for a safety measure if the inputs were shorter. \ No newline at end of file diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..403640cd5 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -9,7 +9,23 @@ In the Chrome console, invoke the function `alert` with one argument, the string What effect does calling the `alert` function have? +// Alert brings a pop up window out and says "Hello world" from the page. It also has a button called "OK" + 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`? + +// Opens a popup box with a text input. The value inside the () is what would display above the input. +// The return value is myname? + +This is the code I did. +alert("Hello world") +undefined +prompt("What is your name") +'Tylerluvslasagne' +let myname = prompt("what is yur name") +undefined +console.log(myname) +VM319:1 I LOVE MY EX +undefined \ No newline at end of file diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..be8a79745 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -13,4 +13,18 @@ Try also entering `typeof console` Answer the following questions: What does `console` store? +// Console is an object that stores properties as fucntions. (Think of import = math, math.sqrt(9)) + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +// It means that you are calling on console to run this particular function in your javascript code. +// console.log: access property(log) inside object(console). +// The . is the property access operator. +// The () contain an argument(s) which run the code. + +My code: +console.log + ƒ log() { [native code] } +console + console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +typeof console + 'object' \ No newline at end of file