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

// The line 3 is just incrementing the counting
4 changes: 3 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,9 @@ 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(initials);

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

9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const dir = filePath.slice(0, lastSlashIndex);
const ext = filePath.slice(lastSlashIndex + 5);

console.log(`The base part of ${filePath} is ${base}`);
console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);


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


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

// represents a whole random number between 1 and 100
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
age = age + 1;

// instead of const, we should use let because it means that the variable can change

let age = 33;
age = age + 1;
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 line console.log can't be before the variable
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
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
// 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

// the .slice is a string method and the number is not a string

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";

// the name of the variable can't start with a number
12 changes: 6 additions & 6 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let carPrice = "10,000";
let priceAfterOneYear = "8,543";
let carPrice = "10,000"; // variable declaration
let priceAfterOneYear = "8,543"; // variable declaration

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
carPrice = Number(carPrice.replaceAll(",", "")); // variable reassignment statement and function call (.replaceall is replacing the comma for a empty space and the number() is converting the string into a number value)
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // variable reassignment statement and function call

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
const priceDifference = carPrice - priceAfterOneYear; // variable declaration
const percentageChange = (priceDifference / carPrice) * 100; // variable declaration

console.log(`The percentage change is ${percentageChange}`);

Expand Down
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 = 2500000; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -11,15 +11,16 @@ 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?
// a) How many variable declarations are there in this program? - six variable declarations

// b) How many function calls are there?
// b) How many function calls are there? - the log(result)

// c) Using documentation, explain what the expression movieLength % 60 represents
// c) Using documentation, explain what the expression movieLength % 60 represents - Represents how many seconds remain from the movie. how many times is 60 in 8784? = 24 so that would be the remainder
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// 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?
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - Represent how many minutes of the movie have pass

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// e) What do you think the variable result represents? Can you think of a better name for this variable? - Represents the film time elapsed and a better name could be : const time elapsed =

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer - yes, because the format is in hours, could works with any positive number.
10 changes: 7 additions & 3 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
Expand All @@ -25,3 +25,7 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. Its creating a new string without the "p"
// 3. adding 0 to 3, so 0399
// 4. create a string with the first two digits
// 5. create a string with the last two digits
Loading