diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..7a75ffd8c 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,10 @@ let count = 0; count = count + 1; +console.log(count); + // 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 the value of the count variable. +// The = operator is an assignment operator, which assigns the value on the right (count + 1) to the variable on the left (count). \ 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..f47b214dd 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,12 @@ 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 ab90ebb28..b13f9492a 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,9 @@ 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(0, lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".")) ; +console.log("dir:", dir); +console.log("ext:", 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 292f83aab..d29072d33 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,16 @@ 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? +console.log(num); + +// In this exercise, you will need to work out what num represents? +// num represents a random whole number between the minimum and maximum values. + // 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 + +//Step 1 Generate a random decimal between 0 and 1 +//step 2 multiplys the random decimal by 100 - 1 = 99 + 1 = 100 +//step 3 math.floor makes it a whole number between 0 and 99 +//step 4 adds 1 to make it a whole number between 1 and 100 \ 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 cf6c5039f..8e3cf8516 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/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 +We don't want the computer to run these 2 lines - how can we solve this problem? +*/ diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..003117be0 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; age = age + 1; +console.log(age) \ 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..fe55e6ea3 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 ? +// what's the error ? The error is that the string is not being printed to the console because there is no console.log statement to output it. -console.log(`I was born in ${cityOfBirth}`); +console.log("I was born in Bolton"); const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..309191559 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,8 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); + + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +10,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 + +/* +Prediction: It wont work because cardNumber is a number and slice() only works on strings. +Error: TypeError - cardnumber.slice is not a function. +Explanation: Numbers dont have the slice method. +*/ \ 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..a5d399d8b 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const hour12HourClockTime = "20:53"; +const hour24HourClockTime = "08:53"; \ 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..37bf8b393 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,22 @@ 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 +// Line 4 has a function call +// Line 5 has a function call +// line 10 has a function call // 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? +// I have spotted the error in line 5 becouse there was a missing comma inside the brackets. // c) Identify all the lines that are variable reassignment statements +// Line 4 and line 5 are variable reassignment statements. // d) Identify all the lines that are variable declarations +// Line 1 +// Line 2 +// line 7 +// line 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// The purpose of this expression is to remove the commas from the string value using the replaceAll(). + diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..8ae1348ea 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -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? +// There is 6 Variable declarations +// Line 1 , Line 3 , Line 4 , Line 6 , Line 7 , Line 9 // b) How many function calls are there? +// There is 1 function call in Line 10 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// The expression movieLength % 60 represents the remainder of the division of movieLength by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// Line 4 removes the leftover seconds, then devides by 60. +// then divides the result by 60 to calculate the total full minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// Result is a formatted time string in hours minutes and seconds. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// I tested diffrent positive numbers and the code work correctly. +// However it well work properly for positive numbers. +// If movielength is negative or a decimal number , the output may not repeesent the time correctly. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..2938150a1 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -22,6 +22,13 @@ 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 +// 1. Stores "399p" as a string +// 2. removes the "p" at the end +// 3. adds zeros at the start if needed to make it 3 digits. +// 4. Takes everything except the last 2 digits as pounds. +// 5. Prints the result in this format: £3.99 -// To begin, we can start with +// I also tested it by changing 399p to 50p and the result was £0.50 thats shows diffrent numbers well have diffrent outputs + +// To begin, we can start wit // 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..04ff2afb5 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -10,9 +10,10 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; -What effect does calling the `alert` function have? +What effect does calling the `alert` function have? It displays a popup message box with a text saying Hello world! and pauses the website in until you click ok to unpause it. 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? The prompt function displays a popup box asking you to enter a text and pausing the page until you click ok or cancel. + +What is the return value of `prompt`? Prompt returns the text entered by the user as a string if the user clicks cancel. diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..f974ac2db 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -12,5 +12,8 @@ Try also entering `typeof console` Answer the following questions: -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +What does `console` store? Console is an object that stores debugging finctions. + +What does the syntax `console.log` or `console.assert` mean? Console.log or console.assert means accesing a fuction inside the console object. + + In particular, what does the `.` mean? The dot '.' is called dot notation and it used to access properties or methods of an object.