Skip to content
Open
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
10 changes: 10 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ 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 the value of the variable `count`.
The `=` operator is an assignment operator,
which means it takes the value on the right side
(in this case, `count + 1`)
and assigns it to the variable on the left side (`count`).
So, it takes the current value of `count`, adds 1 to it,
and then stores that new value back into `count`.
in general, Line 3 is incrementing the value of `count` by 1.
*/

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]}`;
console.log(initials);
// https://www.google.com/search?q=get+first+character+of+string+mdn

7 changes: 4 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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 = base.slice(base.lastIndexOf("."));
console.log (`The directory is : ${dir}
The extension is : ${ext}`);
// https://www.google.com/search?q=slice+mdn
9 changes: 9 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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?
// num represents a random integer between 1 and 100.
// 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
// breaking down the expression into smaller parts.
/* Math.floor(): this will return the largest integer less than or equal to a given number. In this case, it will round down the result of the expression inside the parentheses.
Math.random(): this will return a random floating-point number between 0 (inclusive) and 1 (exclusive). In this case, it will generate a random number between 0 and 1 but never exactly 1.
(maximum - minimum + 1): this will calculate the range of numbers we want to generate. In this case, it will calculate the difference between the maximum and minimum values (100 - 1 = 99)
and add 1 to include both endpoints (99 + 1 = 100).
finally, the code adds the minimum value (which is 1) to the result.
*/

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);
3 changes: 3 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

//The error was ReferenceError: cannot access `cityOfBirth` before initialization
//by swapping the order of the two lines, the error will be fixed.

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
11 changes: 9 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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
// Before running the code, make and explain a prediction about why the code won't work
// i predict that the code doesn't work its because of two things, first i thought its case sensitive things
// the second one is the type of variable, i thought the slice method is only for string type variable.

// 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?
/*
I run the code and it gives me an error that says "TypeError: cardNumber.slice is not a function".
so i checked the type of cardNumber using typeof operator and it returns number.
*/
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
4 changes: 4 additions & 0 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";

// I believe this question is about what the error might be.
// the error is syntaxError: and its because the variable name stats wit a number which is not allowed in Javascript.
// removing the number or use the number next to the string/s.
18 changes: 17 additions & 1 deletion 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,27 @@ 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. including methods used , 2 methods = replaceAll(), methods are called under their object, replaceAll() is called under the string object.
// The lines where a function call is made are:
// Line 4: carPrice.replaceAll(",", "")
// Line 5: priceAfterOneYear.replaceAll(",", "")
// Line 7: console.log(`The percentage change is ${percentageChange}`)

// 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?
//syntaxError: missing ) after argument list, -
//the error is occurring because of a missing "," in the replaceAll() method. in line 5.

// c) Identify all the lines that are variable reassignment statements
// The lines that are variable reassignment statements are:
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

// d) Identify all the lines that are variable declarations
// The lines that are variable declarations are:
// 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;

// 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 into a number by removing the comma from the string.
9 changes: 9 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,23 @@ 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.

// b) How many function calls are there?
// there is 1 function call in this program, which is the 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
// 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 movie length from seconds to minutes.
// The modulo operator (%) returns the remainder of a division operation, so it helps to determine how many seconds are left after accounting for full minutes in the movie length.
// this means 8784 seconds is exactly 146 minutes and 24 seconds.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The expression assigned to totalMinutes will return the total number of minutes only leaving the seconds out.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// the variable holds the hour,minutes and seconds a movie is long, so i prefer to name it movieDuration.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes, this code will work for all values of movieLength because every attributes of the movieLength variable is being calculated and converted to hours, minutes and seconds.
13 changes: 9 additions & 4 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ const penceString = "399p";
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
); // remove the trailing "p" from the string

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // pad the string with leading zeros to ensure it has at least 3 characters
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
); // get the substring representing the pounds by taking all characters except the last two

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.padEnd(2, "0"); // get the substring representing the pence by taking the last two characters and padding it with a "0" if necessary

console.log(`£${pounds}.${pence}`);

Expand All @@ -25,3 +25,8 @@ 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 string to get the numeric part of the price in pence
//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, which is useful for prices less than £1
//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the substring representing the pounds by taking all characters/values except the last two
//5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the substring representing the pence by taking the last two characters and padding it with a "0" if necessary
//6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console
Loading