Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
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
4 changes: 2 additions & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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]}"`;

// https://www.google.com/search?q=get+first+character+of+string+mdn

console.log(initials); // Output: "CKJ"
9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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(0, lastSlashIndex);
const lastDot = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDot);

console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);


// https://www.google.com/search?q=slice+mdn
8 changes: 8 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -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?
/*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?*/
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -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);
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// 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}`);

/*console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";*/
/* The error is that the variable `cityOfBirth` is being used before it is declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement:*/
//The variable were being accessed from the Temporal Dead Zone (TDZ) before it was declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement:

const cityOfBirth = "Bolton";

console.log(`I was born in ${cityOfBirth}`);
11 changes: 10 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
//console.log(typeof cardNumber);
const cardNumberStr = cardNumber.toString();

const last4Digits = cardNumberStr.slice(-4);
console.log(last4Digits); // Output: "4213"

// 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
// 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
// I suspect the code doesn't work because the slice method is being called on a number, but slice is a method for strings. Therefore, I predict that the code will throw an error saying that slice is not a function for numbers.

// i console the typeof cardNumber and it returns number


9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyFourHourClockTime = "20:53";
/*names beginning with $ or _ often carry special conventions:

_name often implies a private/internal variable.
$name is commonly associated with libraries like jQuery or special framework objects.*/
/*For ordinary variables, it's usually clearer to start with a letter and use camelCase and avoid special characters, not starting with a number. and choosing meaningful names that describe the variable's purpose.*/
23 changes: 21 additions & 2 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,11 +12,30 @@ 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
// There are 5 function calls in this file. The function calls are made on the following lines:
// Line 1: replaceAll()
// Line 2: replaceAll()
// Line 5: Number()
// Line 6: Number()
// Line 9: 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?

// 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?
// The error is occurring on line 5., and it's a SyntaxError: missing , The error is due to a missing comma in the replaceAll() method.//The error occurs on line 5. A SyntaxError is thrown because a comma is missing between the two arguments passed to the replaceAll() method. JavaScript uses commas to separate arguments in a function call. The programming term that belongs to the blank is call arguments as that is the actual value passed during a function call. The correct syntax should be replaceAll(",", ""). To fix this problem, we need to add the missing comma in the replaceAll() method on line 5
// c) Identify all the lines that are variable reassignment statements
// The variable reassignment statements are on the following lines:
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,""));

// d) Identify all the lines that are variable declarations
// The variable declaration statements are on the following lines:
// Line 1: let carPrice = "10,000";
// Line 2: let priceAfterOneYear = "8,543";
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
// A declaration is when a variable is created, using let or const.



// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
/* The expression Number(carPrice.replaceAll(",","")) is converting the string value of carPrice, which contains a comma, into a number. The replaceAll() method is used to remove all commas from the string, and then the Number() function is used to convert the resulting string into a number. This allows for mathematical operations to be performed on the value of carPrice without any issues caused by the presence of commas in the string.*/
18 changes: 18 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@ 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 are 6 variable declarations in this program. The variable declarations are on the following lines:
// Line 1: const movieLength = 8784;
// Line 3: const remainingSeconds = movieLength % 60;
// Line 4: const totalMinutes = (movieLength - remainingSeconds) / 60;
// Line 6: const remainingMinutes = totalMinutes % 60;
// Line 7: const totalHours = (totalMinutes - remainingMinutes) / 60;
// Line 9: const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;


// b) How many function calls are there?
// There is 1 function call in this program. The function call is made on the following line:
// Line 10: console.log(result);


// c) Using documentation, explain what the expression movieLength % 60 represents
// The expression movieLength % 60 represents the remainder of the division of movieLength by 60. In this case, it calculates the number of seconds remaining after converting the total length of the movie (in seconds) into minutes. The modulo operator (%) is used to find the remainder when one number is divided by another. So, if movieLength is 8784 seconds, movieLength % 60 will give us the number of seconds that do not make up a full minute.

// 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?
// The expression assigned to totalMinutes calculates the total number of minutes in the movie length. It does this by first subtracting the remaining seconds (calculated in line 3) from the total movie length (movieLength), which gives us the total number of seconds that can be fully converted into minutes. Then, it divides that result by 60 to convert those seconds into minutes. This gives us the total number of complete minutes in the movie length, excluding any remaining seconds.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The variable result represents the formatted string that shows the total length of the movie in hours, minutes, and seconds. A better name for this variable could be "formattedMovieLength" or "movieDuration" to more clearly indicate that it holds the duration of the movie in a human-readable format.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
/* The code will work for all non-negative integer values of movieLength, as it correctly calculates the hours, minutes, and seconds for any given length of time in seconds. However, if movieLength is a negative number or a non-integer value, the code may not produce meaningful results. For example, if movieLength is negative, the calculations for remainingSeconds, totalMinutes, and totalHours will not make sense in the context of a movie duration. Additionally, if movieLength is a non-integer (like a float), the calculations may yield unexpected results due to how JavaScript handles floating-point arithmetic. Therefore, it's best to ensure that movieLength is a non-negative integer for this code to work correctly. Also, it works correctly only when the movieleng is less than 24 hours, because the code does not account for days. If the movie length exceeds 24 hours, the totalHours variable will continue to increase without resetting after 24, which may not be the desired behavior for representing time in a standard format. */
// if movieLength = 90000 seconds, that 25 hours , the variable result will be 25:0:0, which is not a standard representation of time.
// leading zeros , the variable result will always output resuls like H:M:S instead of HH:MM:SS, so if the movie length is 1 hour, 5 minutes and 9 seconds, the variable result will be 1:5:9 instead of 01:05:09.
7 changes: 7 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value.
//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary, .padStart(target Length, padString), adds strings to the start of the string until it reaches the target length, in this case 3, and if the string is already 3 or more characters long, it will not add any padding.
/*4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the price ,paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(0, 1) = "3" it took characters from index 0 to 1*/
/*5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion of the price and ensures it has two digits by padding with a trailing zero if necessary, paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(1) = "99" it took characters from index 1 to the end of the string, then .padEnd(2, "0") adds strings to the end of the string until it reaches the target length, in this case 2, and if the string is already 2 or more characters long, it will not add any padding.*/

/*6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console, using template literals to insert the pounds and pence variables into the string. The output will be in the format "£X.YY", where X is the pounds value and YY is the pence value. In this case, it will output "£3.99".*/

4 changes: 4 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ 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?
// By invoking alert("Hello world!"); the effect it has is that a small modal dialog box pops up at the top of the window browser displaying Hello world!, along with an OK button.

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?
//The effect is similar to the alert one a small modal dialog box pops up with the addition of a text input field and two buttons for 'OK' and 'Cancel', it displays the question What is your name?
What is the return value of `prompt`?
//The return value of the 'prompt' depends on what action the client did , whci is one of two things based on the client actions.it will return whatever the client typed into the text field as string and click 'OK' and this will be stored in the variable myName, and can be verified by typing myName into the console and hitting ENTER.However if the user clicks cancel , it returns null.
Loading