diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..7c7f3e30e3 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; - // 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 is updating variable count by adding 1 to its value. + diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..bc26a8df4e 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[0]}${middleName[0]}${lastName[0]}`; // using string indexing to get the first character of +// each string +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..ed3ae829fe 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -16,8 +16,12 @@ 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(lastSlashIndex - 9, lastSlashIndex);//dir variable gets to "dir part of +// the path by using last instance of "/" as a reference and counting backwards 9 digits to get the beginning of the path +// and uses last instance of "/" as the end of the path, which is "interpret" +const ext = filePath.slice(lastSlashIndex + 5);// ext variable gets the last instance of "/" as a reference and +// counts 5 indexes forward to get the "ext" part of the path which is ".txt" +console.log(`The dir part of the filePath ${filePath} variable is "${dir}".`); +console.log(`The ext part of the filePath ${filePath} variable is "${ext}".`); // https://www.google.com/search?q=slice+mdn \ 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 292f83aabb..30e75bb5ac 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,9 @@ 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 +// num is a random number multiplied by the maximum number(100) plus 1. It is then rounded down to the nearest whole number using Math.floor. This means that num will be a random integer between 1 and 100, inclusive. diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..39f9e5bfba 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ -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 comment it out, this way the computer doesn't read is as code. diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..d8a82f0720 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; // by changing the way we declare the variable from "const" to "let" we allow +// reassignment of the value of the variable age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..d4317fc9b5 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}`); +// The error was that the variable is not defined before the the console.log command. 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..c97907ca94 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +8,9 @@ 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 +// +// ------------------------Answer------------------------ +// Running the code did't meet my predictions. One, the most important thing I did't realize +// is that "slice() method only applies to strings and arrays, +// and the "cardNumber" variable was a number. By converting it to a string, the slice method +// is working correctly now." \ 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 5f86c730bc..2c2c4d7584 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,10 @@ const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const 24hourClockTime = "20:53"; +//what is the task in this exercise? + +// *****************Answer*********** +//Variable names must srart with a letter and here they start with a number +//triggering SyntaxError +//Therefore the they should look like the code below. +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..5b60cefbd9 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,8 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));// coma was missing. const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +11,20 @@ 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 - +// Answer to a): There are 4 function calls in this file, which are on the lines 4, 5, 6 and 7 . +//and additionally, there is a function call on line 9, which is the console.log() statement. So 5 function calls in total. +// // 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? - -// c) Identify all the lines that are variable reassignment statements - +// Answer to b): The error is coming from line 5, where coma is missing in "replaceAll()"" function. +// + //c) Identify all the lines that are variable reassignment statements +// Answer to c) Variables are reassigned on lines: 4 and 5 +// // 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? +// Answer to d) Variables are declared on lines: 1, 2, 6, 7 +// +// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - +// what is the purpose of this expression? +// Answer to e): The expression Number(carPrice.replaceAll(",","")) is replacing all the comas in the string in the variable +//carPrice with an empty string and then turns it into number. +// The purpose of it is that number can now be used to perform mathematical operations. diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..1fd9480b2b 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 = -8784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,24 @@ 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 to a) There are six variables in this program. +// // b) How many function calls are there? - +// Answer to b) I think there one function call in this program and it is "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 to c) The expression movieLength % 60 tels how many seconds will be left after +// full minutes are extracted. +// // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +// Answer to d) The line four calculates how many full minutes are in the movie. +// // 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 +// Answer to e) The variable result represents the total length of the movie in hours, minutes and seconds. +// A better name for this variable could be "formattedMovieLength". +// +// f) Try experimenting with different values of movieLength. Will this code work for all values of +// movieLength?Explain your answer +// Answer to f) This code will work with all values, however giving it a negative value will produce +// negative results. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..90ad6c7d8c 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399p"; +const penceString = "33399p"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -6,6 +6,7 @@ const penceStringWithoutTrailingP = penceString.substring( ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 @@ -24,4 +25,21 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +// Line 1. const penceString = "399p": initialises a string variable with the value "399p" +// +// Line 3. variable "penceStringWithoutTrailingP" declared and assigned first three characters +// of "penceString" using the substring method, removing the trailing "p". +// +// Line 8 . variable "paddedPenceNumberString" declared and assigned the value of "penceStringWithoutTrailingP" +// padded to a minimum length of 3 characters with leading zeros using the padStart method. Which is clever way, +// really to replace it with zeros if number of pence is less than 3 characters long. +// +// Line 10 Variable "pounds" declared and assigned value of "paddedPenceNumberString" but without the last +// two characters. +// +// Line 15. Variable "pence" declared and assigned value of the last two characters of "paddedPenceNumberString" +// and padded to a minimum length of 2 characters with zeros at the end, padEnd method is used once again. +// it is to ensure that if the number of pence is less than 2 characters long, it will be padded with zeros +// at the end. +// +// Line 19. console.log is used to print final output. diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..9cec3cf7ae 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,15 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +// Answer : invoking alert function with "Hello World" string as an input shows a new smaller window where is says +"chrome://new-tab-page says +Hello World +Trying to run the same function with any other parameter prints other parameter to the screen, which makes me realise that the function is already predefined in the V8 somewhere. +// 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`? +// Answer: Running prompt function prompts my to enter my name and then prints it to the console. Which means that prompt function is aready predefined and has input functionality and probably console.log() inside the function. +// diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..d59bab0789 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -14,3 +14,6 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +Answer: I don't think 'console' itself stores anything. Variables store values. 'console' is an object. +'.' after the 'console' allows to add one of the methods like console.log() or console.clear()