Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 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,6 @@ 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 is taking the value of the variable count at line 1, and then adding 1 to it.
// Then it is assigning that value to the variable count.
Comment thread
cjyuan marked this conversation as resolved.
Outdated
4 changes: 1 addition & 3 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ 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

6 changes: 3 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,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(1, lastSlashIndex);
const ext = base.split(".")[1];
Comment thread
cjyuan marked this conversation as resolved.
Outdated

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

// This code generates a random number between 1 and 100 (inclusive of 100).
// Math.random() produces a pseudo-random number greater than or equal to 0 and less than 1.
// That number is multiplied by the total count of possible values we want, in this case 100.
// The + 1 in (maximum - minimum + 1) ensures that 100 is one of the possible values of num.
// the + minimum at the end makes 1 the lowest value possible.
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?
2 changes: 1 addition & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
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}`);
// need to declare city of birth first.

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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
// 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

// Prediction: there will be an error, cardNumber does not have a slice method.
// Slice method only applies to strings and arrays

// Result: TypeError: cardNumber.slice is not a function. Which is the expected error.

// Fix: Casting the cardNumber to a string allows us to use the slice method.
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 TwelveHourClockTime = "20:53";
const TwentyFourHourClockTime = "08:53";
Comment thread
cjyuan marked this conversation as resolved.
Outdated

// variable names can't start with a number
8 changes: 8 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,19 @@ 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
// Total: 5
// 2 in line 4, 2 in line 5
// 1 in 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?
// Error in line 5, missing comma after first arguement in 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, 8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// replaceAll function returns a new string with all commas removed, so that it is a valid input for Number.
// Number takes an input and converts it to a number.
11 changes: 10 additions & 1 deletion Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = -5784; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -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?
// 6

// b) How many function calls are there?
// 1

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// % is the remainder operator in JavaScript. The expression represents the remainder after dividing
// movieLength by 60, in this case: 24.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The total length of the movie in minutes, after taking away the fractional part (the 24 seconds).

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The exact runtime of the movie, converted from seconds into hours, minutes and seconds format.
Comment thread
cjyuan marked this conversation as resolved.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// It works with all positive values of movieLength. For negative values, it produces negative hours, minutes, and seconds.
// This is due to the fact that % is a remainder operator, not a true modulo operator. It always takes the sign of the divided.
// So if you divide a negative number, the remainder will be negative.
21 changes: 20 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 = "9p";

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

// 3. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
// removes the trailing p so that there's a clean number format to work with.

// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// pad the start so that there's always a character (0) in the pound's place, and the 10th and 100th place of the
// fractional part (pence). E.g. for 9 pence, the pre-padded number would be "9", by padding it with 0, you get
// 009, which can easily be formatted as £0.09.

// 9. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
// final two characters will always represent pence, be it "09" for 9 pence, or "90" for 90 pence
// so the pound part will be anything preceding those two characters.

// 14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
// I guess, this is trying to ensure that pence always amounts to at least 2 digits, but it is unnecessary
// as you're always taking the last two digits and padStart in line 8 ensures that the string always has at least 3 characters.

// 18. console.log(`£${pounds}.${pence}`);
// this is just adding a pound symbol at the start and joining the pound and pence parts captured earlier with a dot.
Loading