diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..66ee61450 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -3,4 +3,6 @@ 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 whaWt line 3 is doing, in particular focus on what = we calculate the value of sum operator and put it in left variable. + + diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..aa9d69f65 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -4,7 +4,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. +let initials = + `${firstName.charAt(0)}` + + `${middleName.charAt(0)}` + + `${lastName.charAt(0)}`; + +console.log(initials); -const 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..ef5afac10 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -16,8 +16,10 @@ 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 = filePath.slice(0, lastSlashIndex); +console.log(`The direction of the file is ${dir}`); +const ext = filePath.slice(filePath.lastIndexOf(".") + 1); +console.log(`The extenction of the file is ${ext}`); -const dir = ; -const ext = ; -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..ae3937c49 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -3,7 +3,9 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -// 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 +// In this exercise, you will need to work out what num represents?It gives us a random number between 1-100 +// Try breaking down the expression and using documentation to explain what it means? + minimum shifts it between 1-100 so the minimum number is 1 and the biggest one is 100 + //Math.random gives us a random number between 0-1 and the next parantecec returns 100 +//after that we multiple these two given values between 0-100 and the floor methode rounds down the given value // 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 diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..1a799bb21 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/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? we can put back slash to change it into comments. diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..c3714c46a 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; +console.log(age) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..d57ab0492 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/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 ? +// what's the error? +//ReferenceError: Cannot access 'cityOfBirth' before initialization -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..eb148b7c9 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,9 @@ 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 +// Before running the code, make and explain a prediction about why the code won't work?this function works on string NOT numbers // 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 diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..afbfa6593 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime= "20:53"; diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..db4b67434 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; @@ -11,12 +11,33 @@ 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 +// a) How many function calls are there in this file? Write down all the lines where a function call is made? +//There are 5 function calls: +//replaceAll +//Line 4 +//Number(...) +//Line 4 +//priceAfterOneYear.replaceAll(",", "") +//Line 5 +//Number(...) +//Line 5 +//priceAfterOneYear.replaceAll(",", "") +//Line 10 ,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? - +//error:line 5,SyntaxError: missing ) after argument list,missing a comma between the two arguments. // c) Identify all the lines that are variable reassignment statements +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + // d) Identify all the lines that are variable declarations +//let carPrice +//let priceAfterOneYear +//const priceDifference +//const percentageChange // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//it removes all commas from the string +//converts the string "10000" into the number 10000 +//The purpose is to turn the price from a formatted string into a number diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..4eb7bfc13 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -11,15 +11,28 @@ 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 +// c) Using documentation, explain what the expression movieLength % 60 represents? +//8784 % 60=24 +//The % operator is called the remainder operator. +//It gives you the remainder left over after division. +//we can calculate the number of the left seconds after converting the movie length into whole minutes, 24 seconds left over after converting the movie's total length into whole minutes. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// d) Interpret line 4, what does the expression assigned to totalMinutes mean?This removes the seconds that don't make up a complete minute. +//Then it divides that number by 60 to convert the seconds into whole minutes. +//we have 8784 seconds so -// e) What do you think the variable result represents? Can you think of a better name for this variable? +//8784 - 24 = 8760 +//8760 / 60 = 146 it is the total minutes +// e) What do you think the variable result represents? Can you think of a better name for this variable?creates a formatted representation of the movie's length in hours, minutes, and seconds. +//I can name it the movie duration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + //Works properly for non-negative whole-number seconds; decimals/negative values cause formatting problems + + + diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..161045952 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -22,6 +22,15 @@ console.log(`£${pounds}.${pence}`); // You need to do a step-by-step breakdown of each line in this program // Try and describe the purpose / rationale behind each step +//this function penceString.length-1 removes the last p from string so it values 3 because it contains 4 characters minues 1. +//penceString.substring(0, 3) and it takes the characters from position 0 up to, but not including, position 3. +//const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");This uses padStart() to make sure the string has at least 3 characters. +//const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); +//This line extracts the pounds part. +//line14:penceString = "399p" + +//paddedPenceNumberString is "399". +//The substring() takes the last two characters, so:"399" → "99" +//Then .padEnd(2, "0") checks the string is at least 2 characters long. If it already has 2 characters, like "99", without changing the rest. +//padEnd(2, "0") adds "0" to the end of the string until it reaches a length of 2 and finally line 18 prints the result which is £3.99 -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..37b9a35f7 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -8,8 +8,9 @@ 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? +alert() is a function that displays a message to the user.its return value is undefined. 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 provides a text box where the user can enter their name, along with buttons such as OK and Cancel. +What is the return value of `prompt`? prompt() returns a value.