Skip to content
Open
4 changes: 4 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,7 @@ 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

//Answer: Line 3 is updating the value of the count variable by 1 to the current value of count.
// The = operator reassigns the value of count to be equal to (count + 1), which is the current value of count plus 1.
//This creates a counter that always increases by an increment of 1.
4 changes: 2 additions & 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,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[0] + middleName[0] + lastName[0];
console.log("The initials are", initials);

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

10 changes: 7 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,11 @@ 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 lastDotIndex = filePath.lastIndexOf(".");
const firstSlashIndex = filePath.indexOf("/");
const dir = filePath.slice(firstSlashIndex, lastSlashIndex);
const ext = filePath.slice(lastDotIndex);
console.log(`The directory is ${dir}`);
console.log(`The ext is ${ext}`);

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

//Answer: Firstly a random number that is > or = to = 0 BUT less than 1 is generated, that number is multiplied a 100 and then always rounded down to the nearest whole number and then the minimum value of 1 is added
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?
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
var age = 33;
age = age + 1;

console.log(age);
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// We were trying to call a the variable before it was even initialized / made.

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

console.log(last4Digits);
// 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
Expand Down
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 CivilTime = "8:53pm";
const ContinentalTime = "20:53";
11 changes: 6 additions & 5 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 @@ -12,11 +12,12 @@ 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

// Answer: There are 5 function calls on lines 4, 5 and 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?

// Answer: line 5 there is a comma missing in the replaceAll parameters.
// c) Identify all the lines that are variable reassignment statements

// Answer: Lines 4 and 5
// d) Identify all the lines that are variable declarations

// Answer: Lines 1, 2, 7 and 8
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// Answer: It removes all the commas from the string carPrice and turns it into a number that can be used in calculations
15 changes: 8 additions & 7 deletions 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 = "839f"; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,15 @@ 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?

// Answer: There is 6 variable declarations
// b) How many function calls are there?

// Answer: There is one function call on 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

// Answer: this finds the remainder of movieLength when its divided by 60
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

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

// Answer: The expressions uses the modulo function to work out the remainder value which in this case works out the remaining seconds of the total movie length
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Answer: No it only works as intended when a Non negative integer is used however when Decimal, negative, or string values it does not work as intended.
// Decimal values will display decimal seconds, which does not cause an error, but the output may not be in the expected time format.
// Negative values will produce negative time values, and string values may produce NaN if they cannot be converted into a number.
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"

// 3–6. const penceStringWithoutTrailingP takes the initial constant variable with the value of "399p" and uses the substring function to make a new string
// without the "p". It uses the .length property to return the number of characters in the string and subtracts 1 so that substring stops before the last
// character, which will always remove the "p".

// 8. the next variable paddedPenceNumberString takes the previous string which only has number characters and checks if it is made up of three characters if it is not it
// is padded with "0" at the start of the string till there are three characters the reason for this is the minimum amount of characters needed to represent pounds and
// pence can be represented by is 3.

// 9-12. The next variable pounds takes the previous variable paddedPenceNumberString and uses the substring function to create a new string without the last
// two characters. It uses .length - 2 to stop before the final two characters because those characters represent the pence leaving only the characters
// that represent the pounds.

// 14-16. The next variable pence takes paddedPenceNumberString and uses the substring function starting from two characters before the end of the string.
// This creates a new string containing only the final two characters which represent the pence. The padEnd function then adds "0" to the end of the
// string until it contains two characters making sure that the pence is always displayed using two digits.

// 18. The console.log uses a template literal to combine the pound sign with the pounds and pence variables. A decimal point is placed between the two
// variables so that the final value is displayed as a price in pounds, for example "£3.99".
Loading