diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..1318588d6b 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,8 @@ let count = 0; count = count + 1; +// line basically modifies the variable count by updating and adding 1 to it. So basically count is now equal to the current count + 1. In this instance 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 diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..0084d7abec 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[0] + middleName[0] + lastName[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 ab90ebb28e..6b8072492e 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -13,11 +13,14 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); +console.log(lastSlashIndex) +console.log(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); +const ext = base.slice(4,8); +console.log(ext) +console.log(dir) // 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..f9ffcc9453 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,24 @@ 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 + +//ANSWER +// num represents random whole numbers between 1 and 100 + +// Math.floor is a built in function in JavaScript which basically rounds down a number to +// its nearest whole integer. + +//Math.random is also a built in function for selecting random numbers in this case +//numbers that are between 1 and 100 + +//Therefore num is equal to the a randomly selected number that has been +// rounded down to its nearest whole integer times (maximum - minimum + 1) + minimum +//the computer solves the expression in the bracket first as per mathematics order of operation +// rules so the expression shrinks to Math.floor(math.random()*100) + 1) +// so whatever the random value that the computer generates will be multiplied by 100 and rounded +// or floored down to it's nearest whole integer plush1 \ 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 cf6c5039f7..b999f5f71a 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -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 +// We don't want the computer to run these 2 lines - how can we solve this problem? + +// This is a a syntax error. This text is supposed to be commented out in order for us to not run into this error +// we should add // so that the computer doesn't try to run this text as code . + \ 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 7a43cbea76..81a2cc68d8 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +// the variable age has been declared as constant in order to fix this age will +// need to be declared using let so that it's values can be reassigned diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..5693ce5544 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 city of birth needs to be declared first before attempting to +// print the string diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..0ef3f80986 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/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,8 @@ 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 + +//Prediction the cardNumber is not a string since it is not in "" so I don't +// think the slice() function will work + +// After running the code I got a TypeError \ 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..624013fe81 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/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-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..d913fca26b 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,8 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +// console.log(carPrice) +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -20,3 +21,17 @@ console.log(`The percentage change is ${percentageChange}`); // 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? + + + +// a) There are 2 function calls in this code. replaceAll() in line 4 and 5 and console.log() in line 10 + +// b) There is a SyntaxError on line 5. The replaceAll() function takes 2 arguments +// and this is missing a comma between the 2 arguments + +//c) line 4 & 5 + +// d) line 1,2 7 & 8 + +// e) It is replaces the comma "," in carPrice and removes any spaces so +// everything becomes one string \ 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 47d2395587..f9583d0afc 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 = 10652; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -23,3 +23,18 @@ console.log(result); // 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 + +// Answers + +// a) 6 + +// b) One function call is on this code - console.log() in line 10. + +// c) The remainder (%) operator returns the remainder left over when one operand is divided by a second +// operand. It always takes the sign of the dividend. + +// d) In line 4 the totalHours is calculated by subtracting the remainingMinutes from the totalMinutes and then dividing that answer by 60 + +// e) It is a string representing the time movie time in hours, minutes and seconds + +// f) yes, because the variables for calculating the results use a formulas that will work with any number that is assigned to the movieLength 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 60c9ace69a..b2ffb9e7e3 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -4,17 +4,20 @@ const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); +// console.log(penceStringWithoutTrailingP); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// console.log(paddedPenceNumberString); const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +// console.log(pounds) const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); - +// console.log(pence) console.log(`£${pounds}.${pence}`); // This program takes a string representing a price in pence @@ -24,4 +27,30 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with + +// Answers // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length-1): this +// variable creates a new string that cuts the penceSting to 399,so it basically creates a new +// string from index 0, and removes the last index +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this variable sets +// the penceStringWithoutTrailingP string length to 3, and if the length is shorter than 3 it adds +// "0" in front. +// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2) +// this variable uses the subString function to further slice the paddedPenceNumberString +// string on from the first index and remove the last 2 parts of in. In this case the string goes +// from '399' to just '3' + +// 5.const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +// this variable creates a new string from the paddedPenceNumberString variable using the subString +// function. This time it creates a new string from the last 2 indexes. Furthermore it sets the target +// length for this new variable to 2 and if is is less than 2 it sets a condition to add +// a "0" at the end by using the padEnd() function + + +//6. console.log(`£${pounds}.${pence}`); this is a function call that displays the final amount in +// pounds. It uses string interpolation to directly use the variable values pound and pence and also +// formats the string by adding £ before the values. So the output displayed will be £3.99 + + + diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..eb2f015612 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +I get a pop up message that says chrome://new-tab-page-third-party says Hello,World! 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? +I get a pop up message on my screen that says "what is your name?" and it allows me to enter my name. What is the return value of `prompt`? +It returns the name that I type, Asanda \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..2951067976 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,17 @@ 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? +f log(){[native code]} Now enter just `console` in the Console, what output do you get back? +console{debug:f,error:f, info:f, log:f, warn:f,...} and a list of other functions + Try also entering `typeof console` Answer the following questions: What does `console` store? +It stores the object What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +the "." is an access operator which allows you to access the log or assert method.