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

// Line 3 is reassigning the value of count, its current value 0 plus 1, after line 3 the value of count is 1. The = operator is assigning the new value to the count variable.
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

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.split(".").pop();

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

// https://www.google.com/search?q=slice+mdn
7 changes: 6 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ const minimum = 1;
const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

console.log(num)
// 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
// 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

// Math.random() generates a random decimal number from 0 to less than 1
// Math.floor() rounds down to the nearest whole number
// maximum-minimum+1 gives 100
// Math.random() * (maximum - minimum + 1) gives a random decimal number between 0 and less than 100, and Math.floor() rounds it down to the nearest integer to give a range of 0 to 99, and by adding minimum 1 to it, num is a random integer between 1 and 100 inclusive
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?
//We use comments to ignore these lines so the computer doesn't run them
10 changes: 8 additions & 2 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// trying to create an age variable and then reassign the value by 1

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

// using let as opposed to const is appropriate here as we intend to reassign the value of age

let age = 33
age += 1
console.log(age) //should log 34;
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// 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}`);
// console.log(`I was born in ${cityOfBirth}`);
// const cityOfBirth = "Bolton";
//Uncaught ReferenceError ReferenceError: Cannot access 'cityOfBirth' before initialization is thrown because we are trying to access cityOfBirth before it is declared.

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

18 changes: 15 additions & 3 deletions 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 cardNumber = 4533787178994213;
// const last4Digits = cardNumber.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 will not work because it tries to use a string method on a number

// 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?
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?

// error is TypeError: cardNumber.slice is not a function which is what I expected


// Then try updating the expression last4Digits is assigned to, in order to get the correct value
// by concatenating an empty string the code works as expected
const cardNumber = (4533787178994213).toString();
const last4Digits = cardNumber.slice(-4);
console.log(last4Digits); // should log '4213'

11 changes: 9 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
// const 12HourClockTime = "20:53";
// const 24hourClockTime = "08:53";
//throws SyntaxError because variable name cannot start with a number
const twelveHourClockTime = '08:53'
const twentyFourHourClockTime = '20:53'

console.log(twelveHourClockTime);
console.log(twentyFourHourClockTime);

15 changes: 14 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 @@ -13,10 +13,23 @@ console.log(`The percentage change is ${percentageChange}`);

// 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
//line 4 has 2 function calls - Number and replaceAll
//line 5 has 2 function calls - Number and replaceAll
// line 10 has 1 function call - 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 coming from line 5 due to a missing comma in the replaceAll method. It should be replaceAll(",","")

// c) Identify all the lines that are variable reassignment statements

// lines 4 and 5

// d) Identify all the lines that are variable declarations

//lines 1, 2, 7 and 8

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

//This expression is removing all the commas from the carPrice string and converting it into a number so that mathematical operations can be performed on it.
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 @@ -13,13 +13,25 @@ console.log(result);

// a) How many variable declarations are there in this program?

// There are 6 variable declaration, they are: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result

// b) How many function calls are there?

//There is only one function call, the console.log() in line 10

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

//movieLength % 60 is the remainder of the division of movieLength by 60 i.e it provides the remaining seconds when movieLength is converted to minutes through the use of the modulus operator % that returns the remainder of a division

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// totalMinutes is the total number of full minutes in the movie length , calculated by first removing the remaining seconds then dividing by 60 to convert to minutes

// e) What do you think the variable result represents? Can you think of a better name for this variable?

// result represents the movie length in hours:minutes:seconds format. It would be better to name it formattedMovieLength or movieLengthHMS

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

// No it will not work for all values. In the case of negative values it will result in a negative time which isn't valid. Also there are certain cases where the remaining minutes or seconds are less than 10, which will make the format look weird e.g 0:3:3 which isn't the standard representation of time. This can be fixed by using the padStart method ensuring there are always 2 digits for hours, minutes and seconds. Additionally if the length passes 24 hours we would need to account for days in the format as that would be more appropriate.
13 changes: 12 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const penceString = "399p";
const penceString = "4354301p";

const penceStringWithoutTrailingP = penceString.substring(
0,
Expand All @@ -24,4 +24,15 @@ 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"

//2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length-1) initialises a string variable that has a value of penceString without the last character

//3. const paddedPenceString = pence~StringWithourTrailingP.padStart(3,'0') initialises a string variable that has the value of penceStringWithoutTrailingP but ensures the string is at least 3 characters long by adding 0's to the start if needed

//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) initialises a string variable that has the value of paddedPenceNumberString without the last 2 characters

//5. const pence = paddedPenceNumberString.subString(paddedPenceNumberString.length-2).padEnd(2,'0') initialises a string variale with the value of the last 2 characters of paddedPenceNumberString and ensures the string is at least 2 characters long by adding 0's to the end if needed

//6. console.log(`£${pounds}.${pence}`) prints out the value of pounds and pence in £pounds.pence format by using string interpolation
7 changes: 7 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?

It creates an alert dialog box with a message of whatever is passed into the alert function call

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 creates a dialog box with a message of what is passed to the prompt function and an input field

What is the return value of `prompt`?

This is the response typed into the input field in the prompt dialog window or null if cancel is selected
11 changes: 11 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ 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 an object with built in methods

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

This syntax is accessing the log and assert methods, which are functions, in the console object. Through the use of the dot operator(.) we are able to access properties of an object.
Loading