Skip to content
1 change: 1 addition & 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,4 @@ 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 returns the incurmented value of count after adding 1 to it and assigns this new value back to count
6 changes: 5 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ let firstName = "Creola";
let middleName = "Katherine";
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

17 changes: 9 additions & 8 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// The diagram below shows the different names for parts of a file path on a Unix operating system

// ┌─────────────────────┬────────────┐
// │ dir │ base │
// ├──────┬ ├──────┬─────┤
// │ root │ │ name │ ext │
// " / home/user/dir / file .txt "
// └──────┴──────────────┴──────┴─────┘

// (All spaces in the "" line should be ignored. They are purely for formatting.)


// all spaces in the "" line should be ignored. THey are purely for formatting.

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);
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
// 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(lastSlashIndex+1)
const ext = filePath.slice(lastDotIndexOf(".") +1);

console.log (dir)
// https://www.google.com/search?q=slice+mdn
15 changes: 15 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,18 @@ 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














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?
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
// in this case, we will need to replace the const keyword with let keyword as const vasriable refuses to be reassigned.
let 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 ?

console.log(`I was born in ${cityOfBirth}`);
// we need to declare the variable cityOfBirth first then we can print it out.
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().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

// it seems that the code is not working because the cardNumber variable is not defined as a string.
// my prediction is true.

//we need to add string to the variable cardNumber variable before using the slice method then to print the code out.
16 changes: 15 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// we have to convert the identifiers of the variables to valid ones by removing the 12 and 24 digits and to put them in camel case format.
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";

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

// The twelveHourClockTime and twentyFourHourClockTime variables should store the respective time formats
// 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 variable names to valid identifiers in order to get the correct value
9 changes: 5 additions & 4 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,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

// five fuction calls, in line 4, number(), and replaceAll(). in line 5, number() and replaceAll(), in line 8, 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?

//in line 5, a syntax error because of the missing comma inside the replaceAll method parentheses. we can fix this problem by adding the missing comma.
// c) Identify all the lines that are variable reassignment statements

// in line 4 carPrice variable is reassigned and in line 5 priceAfterONeYear as well.
// d) Identify all the lines that are variable declarations

// four variable declarations in line 1 carPrice variable is declared, in line 2 priceAfterOneYear variable is declared, in line 7 priceDifference variable is declared, and in line 8 percentageChange variable is declared.
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// the purpose of this expression number(carPrice.replaceAll(",","")) is to change a string value that contains commas into a number value by removing the commas first using the replaceAll method and then converting the resulting string into a number using the Number function.
11 changes: 6 additions & 5 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,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?

// six variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result.
// b) How many function calls are there?

// only one fuction call: 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

// the expression movieLength % 60 is using the modulus operator (%) to find the remainder when movieLength is divided by 60.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// the expression assigned to totalMinutes is calculating the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in seconds and then dividing the result by 60 to convert it to minutes.
// 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 string of the movie length in hours, minutes, and seconds. a better name for this variable could be formattedMovieLength or movieDurationFormatted.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes, this code will work for all values of movieLength as long as it is a non-negative integer representing the length of the movie in seconds. the code correctly calculates the hours, minutes, and seconds for any given length of time in seconds.
10 changes: 10 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,13 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"

// to begin we can start with
//1- const penceSring= "399p": initialises a string variable with the value "399p"
//2- const penceStringWithoutTrailingP= a string value "399" is reassigned to penceStringWithoutTrailingP by removing the last character "p" from penceString using the substring method
//3- const paddedPenceNumberString= declared new variable, padStart ensure any argument passed is at least 3 characters long by adding leading zeros if necessary
//4- line 9 a new variable pence is declared and its value comes from the padded string by removing the last two characters which represent the pence.
//5- line 14 const pence= declared variable and the variable is the result after extracting the last two characters from paddedPenceNumberString using substring method and padEnd method is used to ensure that the pence value is always two digits long by adding trailing zeros if necessary
// from the pence string and pads it to two characters to have two digits number.
//6- line 18: console.log (`£${pounds}.${pence}`): returns money amount combing pounds and pence along with the £ symbol
//eg. £3.99
Empty file added number-game-errors.html
Empty file.
Loading