Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 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,8 @@ 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 "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".
2 changes: 1 addition & 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,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.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

// 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(".") + 1);

// 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 @@ -4,6 +4,17 @@ 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?

// Try breaking down the expression and using documentation to explain what it means

The expression Math.floor() //rounds a number down to the nearest integer.
The expression Math.random() //generates a random floating-point number between 0 and 1.
The expression (maximum - minimum + 1) //calculates the range of numbers between the minimum and maximum values.
The expression Math.random() * (maximum - minimum + 1) //generates a random floating-point number between 0 and the range of numbers.
The expression Math.floor(Math.random() * (maximum - minimum + 1)) //rounds that random number down to the nearest integer, resulting in a random integer between 0 and the range of numbers.
Finally, adding minimum to that result //shifts the range to be between the minimum and maximum values.
// 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);

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);
5 changes: 4 additions & 1 deletion 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 ?

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



14 changes: 13 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);

// 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

The code didnt work because the slice method was called on an integer (cardNumber),
but slice is a method that is only available for strings and arrays.
Since cardNumber is an integer, it does not have the slice method,
which will result in an error when the code is run.

// Then run the code and see what error it gives.
The error was: TypeError: cardNumber.slice is not a function

// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
It gives this error because the slice method is not meant for numbers. This is what I predicted, as I expected that calling slice on an integer would result in a TypeError.

// Then try updating the expression last4Digits is assigned to, in order to get the correct value

const last4Digits = cardNumber.toString().slice(-4);
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyFourHourClockTime = "20:53";
24 changes: 24 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,35 @@ 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 4 function calls in this file.
The lines where a function call is made are:

1. carPrice.replaceAll(",", "")
2. Number(carPrice.replaceAll(",", ""))
3. priceAfterOneYear.replaceAll("," "")
4. Number(priceAfterOneYear.replaceAll("," ""))

// 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 the line:
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

The error is occurring because there is a missing comma in the replaceAll method. The correct syntax should be:

priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

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

// d) Identify all the lines that are variable declarations
The lines that are variable declarations are:
1. let carPrice = "10,000";
2. let priceAfterOneYear = "8,543";
3. const priceDifference = carPrice - priceAfterOneYear;
4. 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 performing two operations:
1. It is using the replaceAll method to remove all commas from the string value of carPrice, resulting in a string that represents a number without any formatting (e.g., "10000").
2. It is then converting that string into a number using the Number() function, so that it can be used in mathematical calculations.
12 changes: 12 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,26 @@ 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 variables declared are:
1. movieLength

// b) How many function calls are there?
There is 1 function call in this program. The function called is:
1. 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

// The expression movieLength % 60 represents the remainder when movieLength is divided by 60. This gives us the number of seconds that are left over after converting the total seconds into minutes.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The expression assigned to totalMinutes represents the total number of minutes in the movie, excluding the 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 time string in the format "hours:minutes:seconds".
// A better name for this variable could be formattedTime.

// 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.
//It assumes that the input will always be a valid number of seconds.
//If the input is negative or not a number, the results will be unexpected.
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"

// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1):
// creates a new string variable that removes the last character "p" from the original string

// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
// pads the string with leading zeros to ensure it has at least 3 characters


// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
// extracts the substring representing the pounds by taking all characters except the last two


// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"):
// extracts the last two characters representing the pence and pads it with trailing zeros if necessary


// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console


3 changes: 3 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ What effect does calling the `alert` function have?
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 pops up an imput requesting my name

What is the return value of `prompt`?
The text i typed in the prompt
8 changes: 8 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,20 @@ 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?
ƒ log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
'object'

Answer the following questions:

What does `console` store?
It stores a collection of functions and properties related to debugging and logging.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

The syntax represents accesing a function stored inside an object.
The dot "." is an operator in JavaScript used to look inside an object to access its intertnal properties.
Loading