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
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
//This means that increase the count number by 1 (by adding 1 to the initial number) and maintain the count value after adding 1. E.g 0+1 =1, so the new count now will be 1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.

Can you find out what one-word programming term describes the operation on line 3?

3 changes: 2 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

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

console.log (initials);
9 changes: 6 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,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 dir = ;
const ext = ;
const dir = filePath.slice(0, lastSlashIndex);
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);

// https://www.google.com/search?q=slice+mdn


// https://www.google.com/search?q=slice+mdn
16 changes: 16 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,19 @@ 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


//ANSWERS:
// Num represents a random whole number(integers). In which in this case it can be between 1 to 100.
//Now let me break it down;

//This const minimum = 1; and this const maximum = 100; represent the range from which i want my random numbers to come from.

//This command Math.random() generates a random decimal number from 0(being inclusive) to 1(but not inclusing 1) e.g 0.23, 0.87, 0.001 or 0.999 but it will never generate 1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:

We can also use the concise and precise interval notation to describe a range of values.

  • [, ] => inclusion
  • (, ) => exclusion

For example, we can say Math.random() generates a random decimal number in [0, 1).

// This command (maximum - minimum + 1) is a calculation of the Maximum and Minimum number i.e, 100-1+1=100
// This command Math.floor helps to remove any decimal point and round numbers down to the nearest whole number. e.g from 45.9 to 45
// This command +Minimum helps to add the minimum number in our range inorder to increase the numbers to 100(incusive)

console.log (num)

//After logging and running num, I had these series of numbers: 12, 66, 36,64,9,91....
8 changes: 6 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
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?

//Answer:

//By turning them into comments(by using //) just like this setence.
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// 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);


//I had to change the variable (const) to (let) because a value assigned to (const) can not be assign again, while with (let) it can be reassigned
4 changes: 3 additions & 1 deletion 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}`);

//It is important to declare a variable before using it.
7 changes: 6 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);
Comment on lines -1 to 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose you were not allowed to modify the statement const cardNumber = 4533787178994213;
(that is, keep the variable's value unchanged).
How would you modify the code (through type conversion) so that you can still use .slice(-4) to extract the last 4 digits from the given number.


// The last4Digits variable should store the last 4 digits of cardNumber
Expand All @@ -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

console.log(last4Digits)


//The number attributed to the value cardNumber is not a String, so we need to make the make a string.
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 = "20:53";
const 24hourClockTime = "08:53";
const formatAs12HourClockTime = "20:53";
const formatAs24hourClockTime = "08:53";

console.log(formatAs12HourClockTime)
console.log(formatAs24hourClockTime)

//Variable names do not start with numbers.
15 changes: 13 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 @@ -11,12 +11,23 @@ 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
// a) How many function calls are there in this file? Write down all the lines where a function call is made:
// 5 which are: 2 number(), 2 replaceAll() and 1 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?
// The error is on line 5, there is a missing comma that needs to seperate the arguments of replaceAll().Will fix it by putting the comma.

// c) Identify all the lines that are variable reassignment statements
// Line 4 and 5

// d) Identify all the lines that are variable declarations
// Line 1, 2, 7 and 8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// The purpose is to:

// Remove formatting (commas) from a number string

// Convert the cleaned string into a real number

// Allow mathematical calculations to be performed
8 changes: 8 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,22 @@ 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?
// 6 variable declaration. Which are movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result

// b) How many function calls are there?
// 1 functions, which is Console.log

// c) Using documentation, explain what the expression movieLength % 60 represents
// It represents the remainder expression. This means that the remainder operator returns the remainder left over when one operand is divided by a second operand.
//
// 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?
// This command calculate the number of hours in the expression then extract the leftover minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// It creates a formated string. for example: 2:30:23. That is the movie duration formated in Hours:Minutes:Seconds.
//Better names could be; FormatedDuration or MovieDuration or FormatedTime.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All names look good.

Please note that in JS naming convention, variable names usually begins with a lowercase letter. Names starting with an uppercase letter are used for built-in and custom data types (e.g., Math)


// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// It would Works for positive integers only; not ideal for negatives, decimals, or proper formatting.
19 changes: 19 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,22 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
//For line 3 and 5 (const penceStringWithoutTrailingP = penceString.substring 0, penceString.length - 1)= substring(start, end) extracts part of a string.

//0 means start at the beginning.

//penceString.length - 1 means stop before the last character.

//For "399p":

//length = 4

//4 - 1 = 3

//substring from 0 to 3 → "399"

// The purpose is to;

//Removes the "p" at the end of the string.

//Leaves only the numeric value "399"
Loading