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
1 change: 1 addition & 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,4 @@ 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 reassigning the value of the variable, = sign is used to reassign the value of count to increment by 1.
3 changes: 1 addition & 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,6 @@ 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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

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

10 changes: 6 additions & 4 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ 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 secondCharacterIndex = 1;
const startingPointForExtension = filePath.lastIndexOf(".");

const dir = ;
const ext = ;

// https://www.google.com/search?q=slice+mdn
const dir = filePath.slice(secondCharacterIndex, lastSlashIndex);
const ext = filePath.slice(startingPointForExtension + 1, filePath.length);
console.log(`The dir part of ${filePath} is ${dir} and the ext part is ${ext}`);
// https://www.google.com/search?q=slice+mdn
6 changes: 6 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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 represent any value between 1 to 100.
Math.floor is a method that rounds a number down to the nearest whole number.
Math.random is a method returning any number that is greater than or equal to 0 and less than 1.
first of all i will try to get a value from 0 to less than 1 from Math.random and multiple it by 100
and apply Math.floor to the result which will give me the integer number and then add the minimum value i.e. 1 */
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -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?
/*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? */

/*when we try to write comment and instruction and we want the computer not to run it we can comment them using // for single line and /* for multiple lines. */
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;
// To reassign a value of age we have to use let not const.
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 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 code try to log the variable before declaring the variable
// if we declare and initialize the variable first then we can use it.
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,3 +7,6 @@ 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
/* the code is not working because of the variable type which is .slice method work on
string and array variable types not on number variable types to fix it we can change the variable type to
string variable type by adding double quotation marks to the variable.*/
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const hourClockTime12 = "20:53";
const hourClockTime24 = "08:53";

// Numbers are not allowed as the first character in naming of variables.
15 changes: 15 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ 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 code.
1) Number(carPrice.replaceAll(",","")); line 4.
2) Number(priceAfterOneYear.replace("," "")) line 5.
3) carPrice.replaceAll(",", "") line 4.
4) priceAfterOneYear.replaceAll("," "") line 5.
5) console.log(`The percentage change is ${percentageChange}`); line 10. */

// 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 coming from line 5 and the error is missing between the arguments.

// c) Identify all the lines that are variable reassignment statements
/*on line 4- carPrice = Number(carPrice.replaceAll(",", ""));
on line 5- priceAfterOneYear = Number(priceAfterOneYear.replaceAll(","), "")*/

// d) Identify all the lines that are variable declarations
/* 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 doing changing the value of "10,000" to "10000" because comma count as part of a character after that
changing the string variable type to number variable type. */
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 declaration.

// b) How many function calls are there?
// there is only one function call.

// 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 returns of the remainder after dividing one number by another
in this case 8784 % 60 and it return the remainder 24. */

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//This expression calculates the total full minutes in the movie by removing leftover seconds and converting seconds to minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
//result represent the total movie length using hours,minutes and seconds,the better name can be totalMovieLength.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
/*the code works for different values of movieLength it present the input movieLength by calculating the remainder and subtracting
it with the initial input and using the method for the finding of the value for the rest of the variables and assign the values withe
the variables of hours,minutes and seconds */
24 changes: 23 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,26 @@ 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"
// 1. const penceString = "399p": initializes a string variable with the value "399p"

/* 2. const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
); : this part of the code have two steps,
- inside assigning of variable there is a function call that replace the string "399p" by "399"
- then assigning the variable penceStringWithoutTrailingP with new string "399" */

/* 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this initializes new string value that have
3 character if it's less than 3 it will add "0" in front of the string.*/

/* 4. const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
); : this part of the code assigning const pound with value of string that length is
reduced by -2 . */

/* 5. const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0"); : let's break it down this code parts it have two steps first one is .substring(paddedPenceNumberString.length - 2)
Takes the last 2 characters of the string and the second is .padEnd(2, "0") Ensures the result
is at least length 2 if the length less than 2 it will add 0 at the end of the string. */
Loading