Skip to content

Manchester | ITP-May-2025 | Chukwuemeke Ajuebor | Module-Structuring-and-Testing-Data | Sprint-1 #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
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 is 'assigning' count to a value of the original value of count, plus one.
3 changes: 2 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,8 @@ 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

13 changes: 11 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ 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 = ;
//To get the directory path we have to get a slice between two point,
//the beginning and the start of the last slash index which is stored
//in the variable lastSlashIndex."""

const dir = filePath.slice(0, lastSlashIndex);
console.log(`The directory part of ${filePath} is "${dir}".`)

// To get the directory path we have to create last index of . as well
let lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex) ;
console.log(`The extension part of ${filePath} is "${ext}".`)

// 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 @@ -6,4 +6,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// 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
// - Math.random() will create a floating point (decimal) between 0 and 1 but always less than 1.
// - Math.floor() gets the decimal multiplied by 100 and strips it down to the nearest whole number (integer)

// Try logging the value of num and running the program several times to build an idea of what the program is doing
// The first part of the num expression ensures we have a two digit number between 0 and 99. And the best we can get is 99.
// The addition of the minimum, 1 in this case ensures num can also be 100.
// This ensures that both the "minimum" and "maximum" value can be part of the range of generated answers for the "num" variable.
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
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 can solve this by simply using the double forward slash (quote sign)
3 changes: 3 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

const age = 33;
age = age + 1;

//TypeError: Assignment to constant variable.
// The second line clearly will not work since age was declared to be constant and CANNOT change.
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// It is a reference error and it is as a result of the variable being accessed before it is created
// The first line shoulfd come before the second line

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

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 code won't work because the variable "cardNumber" is not a string.
// Since it is a constant variable, we will have to change directly by putting quote signs around it to make it a string.
12 changes: 10 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
//const 12HourClockTime = "20:53";
//const 24hourClockTime = "08:53";

// In the above, error will occur as Variable names are not allowed to start with a number.
// This means that we must modify the names slightly.

const Hour24ClockTime = "20:53";
const Hour12ClockTime = "08:53";

console.log(Hour24ClockTime)
11 changes: 7 additions & 4 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,14 @@ 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

// There are three; Ln4, Ln5, Ln10.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 lines with function calls on them. How many function calls are there in total?

// 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 as a result of the two arguments in Ln5 not being seperated
// c) Identify all the lines that are variable reassignment statements

// Ln4, Ln5,
// d) Identify all the lines that are variable declarations
// Ln1, Ln2, Ln7 and Ln8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// The purpose is to take replace the commas in the number with "nothing" so that
// the number string can be converted to an actual number.
9 changes: 8 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 = 34; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,21 @@ 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?
// There are 6 variable declarations

// b) How many function calls are there?
// There is no function call.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you using to view the result variable? Are you sure there are 0 function calls?

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// That is the remainder operator and outputs the leftover after division of one operand by the other.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//It takes the total movie duration in seconds and removes the remainder that would come about if the
//total seconds were divided by 60: That way, line4 is sure to bring a whole number back.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
//It represents the movie duration in the format; HH:MM:SS. A good name would be "movieduration"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that "movieduration" offers a clear enough difference to the earlier "movieLength" variable?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Yes it will as long as the minimum movielength is 1 sec. The divided operand will always be returned if the dividing operand can go into it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of any cases where the output might not look correct?

12 changes: 10 additions & 2 deletions 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 = "1509p";

const penceStringWithoutTrailingP = penceString.substring(
0,
Expand All @@ -23,5 +23,13 @@ console.log(`£${pounds}.${pence}`);
// You need to do a step-by-step breakdown of each line in this program
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// Rational behind each step
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. Lns3-6 strip off the p using .substring() with indexing
// 3. Ln8 limits the string characters to 3 and will pad up from the front with zeros to get
// the 3 characters. it uses the pad.start() method with the arguments (3,"0")
// 4. Lns9-12 uses substring method again to fetch out the first character only.
// 5. Lns14-16 fetches the last two characters using the substring method again and uses the
// padstart method to make use there will always be a "0" added to make sure it is two characters
// if needed.
// Ln18 outputs the pound and pence literals