Skip to content

Sheffield | May-2025 | Declan Williams| Sprint-1 #496

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 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
14 changes: 9 additions & 5 deletions .github/pull_request_template.md

Choose a reason for hiding this comment

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

Instead of changing the pull request template text file, do you know where it would be better to place your PR comments so they show in the github UI?

Copy link
Author

Choose a reason for hiding this comment

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

when i send in the pull request i can then edit it there before posting.

Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ If your PR is rejected, check the task list.

Self checklist

- [ ] I have committed my files one by one, on purpose, and for a reason
- [ ] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
- [ ] I have tested my changes
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
- [ ] My changes meet the [requirements](./README.md) of this task
- [x] I have committed my files one by one, on purpose, and for a reason
- [x] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
- [x] I have tested my changes
- [x] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
- [x] My changes meet the [requirements](./README.md) of this task

## Changelist

Briefly explain your PR.

. Made changes/fixes to the errors in sprint 1.
. Have gone through and done all key exercises of sprint 1.
. Also gone through and answered the questions of mandatory-interprets from sprint 1.

## Questions

Ask any questions you have for your reviewer.
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 updating the value of the count variable by adding 1 to its current value. The = operator is used for assignment, meaning it takes the value on the right (count + 1) and assigns it to the variable on the left (count).
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]}`;
// the above code uses the bracket notation to access the first character of each string.

console.log(initials); // CKJ
// https://www.google.com/search?q=get+first+character+of+string+mdn

11 changes: 9 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,14 @@ 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 = ;
// Use the slice method to extract the dir and ext parts
const dir = filePath.slice(0, lastSlashIndex);
console.log(`The dir part of ${filePath} is ${dir}`);


// Use the slice method to extract the ext part
// The ext part is the part after the last dot in the base part
const ext = base.slice(base.lastIndexOf(".") + 1);
console.log(`The ext part of ${filePath} is ${ext}`);

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

// This code generates a random number between 1 and 100, inclusive.
// The Math.random() function generates a random floating-point number between 0 (inclusive) and 1 (exclusive).
// The expression (maximum - minimum + 1) calculates the range of numbers we want to include.
// By multiplying Math.random() by this range, we scale the random number to fit within the desired range.
// The Math.floor() function rounds down the result to the nearest whole number.
// Finally, we add the minimum value to ensure the result starts from the minimum value.
5 changes: 3 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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 solved this problem by using a comment so the computer ignores the lines.
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;
let age = 33;
age = age + 1;
console.log(age);

//this error was solved by using the let keyword to declare the age variable, allowing it to be reassigned later instead of using const, which would have caused an error if we tried to reassign it.
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// 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}`);
// console.log(`I was born in ${cityOfBirth}`);
// const cityOfBirth = "Bolton";

// The error is that `cityOfBirth` is being used before it has been declared.
// To fix this, we needed to declare `cityOfBirth` before using it in the console.log statement.

// Here's the corrected code:
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
13 changes: 12 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// const cardNumber = 4533787178994213;
// const last4Digits = cardNumber.slice(-4);
// prediction: The code will not work because the `slice` method is being called on a number and has not yet been converted into a string.

// this code will throw an error.
// console.log(last4Digits);
// The error i was given: cardNumber.slice is not a function
// Explanation: The error occurs because cardNumber is a number, and the slice method is for a string method.

// To fix this, we need to convert `cardNumber` to a string before using the `slice` method by adding .toString() to the cardNumber variable.
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits); // This should now correctly log "4213"

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js

Choose a reason for hiding this comment

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

Can you explain your choice for the changes you made in this file?

Copy link
Author

Choose a reason for hiding this comment

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

I made these changes because you can't start a variable with a number and it throws an error.
and two the changes to the times inside the variables because a 12 hour clock can only go to "12.59" and then goes back to "1" but i have noticed that i made the error of making the 12 hour clock as "AM" when the 24 hour clock tells me its "PM" and not "AM".

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "08:53 am";
const twentyFourHourClockTime = "20:53";
18 changes: 17 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js

Choose a reason for hiding this comment

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

a) You have identified the lines where there are function calls. Are you sure there are only 3? How do you decide when something is a function call?
b) c) d) Good answer
e) Good detailed explanation!

Copy link
Author

Choose a reason for hiding this comment

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

a) i did believe there was only 3 function calls as i was overlooking the function "number" and just thinking of the .replaceAll functions on lines 4 and 5 after going over it with the teacher during workshop. so the total of functions being called is 5 in total (on lines 4 and 5 there is two function calls in each line and then the last function being called is the console.log on line 10)

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,27 @@ 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 is three functions being called in this file.
// 1. Number(carPrice.replaceAll(",", "")) which is on line 4.
// 2. Number(priceAfterOneYear.replaceAll("," "")) which is on line 5.
// 3. console.log(`The percentage change is ${percentageChange}`) which is on 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?
// Answer: An error occurred on line 5 because there was a missing comma in the function call and that was causing a syntax error.
// To fix this I added the missing comma in the function call on line 5.

// c) Identify all the lines that are variable reassignment statements
// Answer: there are two variable files are reassignment statements in this file. as we declared the variables on lines 1 and 2 with the let statements.
// 1. carPrice = Number(carPrice.replaceAll(",", "")); on line 4.
// 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); on line 5.

// d) Identify all the lines that are variable declarations
// Answer: there is four variables declared in this file. as they are defined with the statements "let and const".
// 1. let carPrice = "10,000"; on line 1.
// 2. let priceAfterOneYear = "8,543"; on line 2.
// 3. const priceDifference = carPrice - priceAfterOneYear; on line 7.
// 4. const percentageChange = (priceDifference / carPrice) * 100; on line 8.

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// Answer: this expression converts the string value of carPrice which contains a comma into a number by first removing the comma using the replaceAll method and then converting the resulting string to a number using the Number function. This is necessary because mathematical operations require numeric values and the original value of carPrice is a string with a comma, which would not work correctly in calculations.
// its purpose is to ensure that the carPrice variable holds a numeric value so that math can be done with the code and be able to work out the percentages.
7 changes: 7 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js

Choose a reason for hiding this comment

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

a) How is the program calculating the number of hours in a film?
b) When you see the result of this code running, how do you see it?
c) d) good answer
e) How do you think your suggestion of movieDuration compares to the earlier movieLength - is it clear what is different between these?
f) Can you find any cases where the result might not look like what we typically expect when dealing with time formats?

Original file line number Diff line number Diff line change
Expand Up @@ -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?
// Answer: they are 5 variable declarations which are all defined by using const variable.
// they are movieLength, remainingSeconds, totalMinutes, remainingMinutes, and result.

// b) How many function calls are there?
// Answer: there are no function calls in this program all the code is just variable declarations and assignments.

// c) Using documentation, explain what the expression movieLength % 60 represents
// Answer: The expression `movieLength % 60` calculates the remainder when `movieLength` is divided by 60. this is whats used to find the remaining seconds after converting the total movie length from seconds to minutes.
// 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?
// Answer: The expression "(movieLength - remainingSeconds) / 60" calculates the total number of minutes in the movie by first subtracting the remaining seconds from the total movie length in seconds and then dividing that result by 60 to convert seconds to minutes. This gives us the total minutes of the movie excluding the remaining seconds.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// Answer: The variable "result" represents the formatted time of the movie in the format "hours:minutes:seconds". A better name for this variable could be "movieDuration" to make it clearer that it holds the duration of the movie in a readable format.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Answer: Yes this would work for all different values of "movieLength" as long as the value is a non-negative integer. The code correctly calculates the hours, minutes, and seconds regardless of the total length of the movie in seconds. If the value of "movieLength" is negative it would still work but would yield a negative time format which may not make sense in a real-world context and produce errors.
7 changes: 6 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ console.log(`£${pounds}.${pence}`);
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 1. const penceString = "399p": initializes a string variable with the value "399p"
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing 'p' from the string, resulting in "399"
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399"
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part from the padded string, which is "3"
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part from the padded string, ensuring it has 2 digits, resulting in "99"
// 6. console.log(`£${pounds}.${pence}`): logs the final formatted price in pounds, which is "£3.99"