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: 2 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,5 @@ 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
// = It assign the value of the variable count added to 1, it's called Incrementing
// Also Line 3, could be written as such count++; according to doc
7 changes: 6 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,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.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
// I understood that charAt(0) gets the first character of the string. also I can concatenate strings with the + operator
// I can also use bracket notation/ Index access to get the first character of the string like this: firstName[0] + middleName[0] + lastName[0]

console.log(initials);


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

4 changes: 2 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,7 @@ 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("."));

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

console.log(num);

// I understand that Math.random() generates a random number between 0 and 1,
// and multiplies it by the range (maximum - minimum + 1) to get a number in that range.
// and then adds the minimum to shift the range to start from the minimum value 1 -> 100 rather than 0 -> 99.
// finally, Math.floor() rounds the number down.

// docs for Math.random() and Math.floor() I used:
// https://www.google.com/search?q=Math.random+mdn
// https://www.google.com/search?q=Math.floor+mdn
5 changes: 3 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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?
// by simply commenting out the lines with // the computer will ignore these lines and not run them
11 changes: 10 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
// const age = 33;
// age = age + 1;

// this code will throw an error because age is declared as a constant and we cannot reassign a new value to a constant variable

// To fix this error, we can change the declaration of age from const to let

let age = 33;
age = age + 1;

// Now the code will work without throwing an error, and the value of age will be updated to 34.
2 changes: 2 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// The error is that we are trying to use the variable cityOfBirth before it has been declared and assigned a value.
4 changes: 4 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ 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 error is that cardNumber is a number and the slice method is a string method, so we cannot use slice on a number.
12 changes: 11 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";



console.log(12HourClockTime);
console.log(24hourClockTime);

// it throws a SyntaxError: Invalid or unexpected token because variable names cannot start with a number.
// The error is that we are trying to assign a string value to a variable that starts with a number, which is not allowed in JavaScript.
// Variable names cannot start with a number.

19 changes: 19 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,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 lines where a function call is made are:
// Line 1: carPrice.replaceAll(",", "")
// Line 2: priceAfterOneYear.replaceAll(",", "")
// Line 3: Number(carPrice.replaceAll(",", ""))
// Line 4: Number(priceAfterOneYear.replaceAll(",", ""))
// Line 5: 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?
// The error is occurring in line 5, because it's missing a comma between the two arguments of the replaceAll method.
// to fix this problem, we can add a comma between the two arguments: priceAfterOneYear.replaceAll(",", "")

// c) Identify all the lines that are variable reassignment statements
// there are 2 variable reassignment statements in this file. The lines where a variable reassignment is made are:
// Line 4 and 5 where we are reassigning new values to the variables
// carPrice and priceAfterOneYear after converting them to numbers and removing the commas.

// d) Identify all the lines that are variable declarations
// there are 4 variable declarations in this file. The lines where a variable declaration is made are:
// Line 1: let carPrice = "10,000";
// Line 2: let priceAfterOneYear = "8,543";
// Line 6: const priceDifference = carPrice - priceAfterOneYear;
// Line 7: const percentageChange = (priceDifference / carPrice) * 100;

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// To remove the commas from the string carPrice and convert the resulting string to a number.
// Then, the Number function is used to convert the resulting string into a number data type,
// which can be used for mathematical operations.
11 changes: 11 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,25 @@ 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.

// b) How many function calls are there?
// There is 1 function call, which is console.log(result).

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// % is Remainder operator. In this case, movieLength % 60 gives us the number of seconds
// that are left after we have taken out all the full minutes from the movie length.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// calculates the total number of minutes in the movie length,
// excluding the remaining seconds that are less than a full minute.

// 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 time in hours, minutes, and seconds.
// A better name for this variable could be movieFormattedTime.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// This code will work for all non-negative integer values of movieLength.
// However, if movieLength is a negative number, the result will be weird format with negative numbers.
// Moreover, if movieLength is not an integer, the result will also be weird format with decimal numbers.
9 changes: 9 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,12 @@ 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 "p" from the string to get "399"
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensure it has at least 3 characters, resulting in "399" ,
// for example if the input was "99p", it would become "099" after padding, ensuring we can correctly extract pounds and pence in the next steps.
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
// extracts the pounds part by taking the substring from the start to the length minus 2, resulting in "3"
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"):
// extracts the pence part by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99"
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
In other words, do we really need .padEnd(2, "0") in this script?

// 6. console.log(`£${pounds}.${pence}`):
// outputs the final formatted price in pounds and pence, which is "£3.99"
5 changes: 5 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
An alert message displays in chrome, the content of the message is the webpage or the website says the string i typed in an alert way.

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?
It allows you to input a value in box the browser displays, in this example myName was assigned using = with a value i inputted after running the code.

What is the return value of `prompt`?
The string you input in the field. but after looking more into it,
there is an edge case where the user can click cancel in this situation the return value is null which means absences of value.
15 changes: 15 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@ In this activity, we'll explore some additional concepts that you'll encounter i
Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
console.log
ƒ log() { [native code] }
ƒ stands for "function"
[native code] part just means it's a function built in so we can't see the actual underlying JavaScript code for it.

Now enter just `console` in the Console, what output do you get back?
console
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
I think it gives a options of methods i can use with the object console.

Try also entering `typeof console`
typeof console
'object'
from the name i can understand that typeof tells you the variable type so for console its object type.

Answer the following questions:

What does `console` store?
It stores a collection of methods.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
It means that i want to use a method (e.g. `log` or `assert`) that belong to an object (e.g. `console`)
`.` is dot notation, it means get the method from the object.