Skip to content

Sheffield | May-2025 | Hassan Osman | Sprint-1 #469

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 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
209ea8f
explained line 3 - variable reassignment
HassanOHOsman May 29, 2025
cf11f38
declared variable stores initial of each word
HassanOHOsman May 29, 2025
9751116
created 2 variables to store different filepathes
HassanOHOsman May 30, 2025
c263fad
Completed Math object * its methods exercises
HassanOHOsman May 30, 2025
8ab5a4e
Commented to avoid running my lines of code
HassanOHOsman May 30, 2025
e8108f8
SyntaxError solved by commenting
HassanOHOsman May 30, 2025
5c1b48b
declaration keyword changed to let to solve error
HassanOHOsman May 30, 2025
2a36aae
ReferenceError avoided by declaring variable first
HassanOHOsman May 30, 2025
064ecb3
last4Digits value updated to avoid error message.
HassanOHOsman May 30, 2025
547fbeb
renamed variables to avoid syntax error
HassanOHOsman May 30, 2025
608f18d
added comma between inputs (line 5) to solve error
HassanOHOsman Jun 2, 2025
47d435e
completed time format
HassanOHOsman Jun 2, 2025
408a4f2
explanation for the code provided
HassanOHOsman Jun 2, 2025
e57e590
V8 questions answered
HassanOHOsman Jun 2, 2025
d1e40e4
answered all questions
HassanOHOsman Jun 2, 2025
b0469be
updated = described line 3
HassanOHOsman Jun 20, 2025
a6e7a48
simplified description - used technical terms
HassanOHOsman Jun 20, 2025
1042135
changed variable names to meet JS requirements
HassanOHOsman Jun 20, 2025
6dd1748
updated answer for variable declaration question
HassanOHOsman Jun 20, 2025
a6bfabe
rephrased my answer for the last question
HassanOHOsman Jun 20, 2025
41eff9e
updated my answer for the last question
HassanOHOsman Jun 20, 2025
d94c7bd
rephrased my answer for Q -f
HassanOHOsman Jun 20, 2025
5203cb7
changed my response to the last question
HassanOHOsman Jun 20, 2025
616652d
changed some of my answers
HassanOHOsman Jun 20, 2025
ec14852
updated response to last question
HassanOHOsman Jun 23, 2025
7c5701d
corrected my response to the 4th Q
HassanOHOsman Jun 23, 2025
c93411c
updated my responses
HassanOHOsman Jun 23, 2025
a9cdc03
updated response for "What does `console` store?"
HassanOHOsman Jun 24, 2025
cac3613
Edited answer 4 What's the return value of prompt?
HassanOHOsman Jun 24, 2025
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
6 changes: 6 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,9 @@ 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: in line 3, the variable count gets reassigned a new value which is the sum of the old value and 1.
In other words, the variable count is now adding 1 to its old value to obtain a new value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.

Can you find out what one-word programming term describes the operation on line 3?

Copy link
Author

Choose a reason for hiding this comment

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

Done!

*/

2 changes: 1 addition & 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,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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

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

4 changes: 2 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,7 @@ 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 dir = filePath.slice(1,lastSlashIndex);
const ext = filePath.slice(filePath.indexOf("."));

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

/*
1. num represents any random whole number (integer) between 1 and 100 (both included)
2. Math.floor(x) it rounds down x to a value that is less than or equal to x, while Math.random() it generates random
numbers that are equal to 0 and less than 1.
3. before we multiply (Math.random() by (maximum - minimum + 1) or vice versa, each expression gets evaulated
first on its own. Math.random() leads to an integer between 0 and less 1, while (maximum - minimum + 1)) evaluates
to 100. Then multiplication comes into place and we get floats from 0.00 and less than 100. Having Math.floor()
as a method basically means we now have random integers from 0 and 99. By considering the last part of the value
assigned to num, we now have random integers from 1 and 100 (both included).
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. A concise and precise way to describe a range of values is to use interval notation.
    For example, we can say Math.random() returns a random number in the interval [0, 1).

  2. Your description is correct but is a little bit verbose.
    Could you try using ChatGPT to find a clearer, more concise way to describe the code?

Copy link
Author

Choose a reason for hiding this comment

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

Done

4. Done!
*/
17 changes: 16 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
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 don't want the computer to run these 2 lines - how can we solve this problem?

/*
I got "SyntaxError: Unexpected identifier" error message. It happen because the 2 lines don't make sense.
the computor sees the first word and it assumes a variable or a function is being declared but then when
it reads the resut of the sentence it breaks as this is not how an identifier is being used and formed in
a programme.
To avoid this issue, we can just simply comment the 2 lines, just like what I am doing here!

*/

/*
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?
*/

12 changes: 12 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,15 @@

const age = 33;
age = age + 1;

/*
I got this error message "TypeError: Assignment to constant variable." after running
my code. It happened because when assigned a value to an identifer using const -short
for constant - it emplies that we have no intention of changing the value. it remains
constant. the second line the variable get reassigned a new value and therefore the
error message above showed up.
To solve this issue the variable age could simply be declared via "let" as seen below:
*/

let age = 33;
age = age + 1;
12 changes: 12 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,15 @@

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

/*
The error message "ReferenceError: Cannot access 'cityOfBirth' before initialization
at Object.<anonymous> " comes up because when the computor reads the first line it
recognised that cityOfbirth is an identifer however it get confused as it has not
been declaed beforehand and runs into an error as a result. To overcome this issue
and access cityOfBirth, simply declare it in the 1st line and then in the 2nd line
use console.log() to display its value to the terminal as seen below:
*/

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

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


/*
This error message was thrown after running the code "TypeError: cardNumber.slice is not a function".
It simply happned because ".slice()" is not a method associated with integers but strings & arrays.
To avoid this issue the value of last4Digits should be as below:
*/

const last4Digits = cardNumber.toString().slice(-4);
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
//const 12HourClockTime = "20:53";
//const 24hourClockTime = "08:53";

// to avoid the syntax error after running the above lines of code do as below:

const ClockTime12Hour = "20:53";
const ClockTime24hour = "08:53";
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Have you also noticed the variable names do not quite match the values assigned to the variable?

  • In JS naming convention, variable names (include identifiers declared using const) usually begins with a lowercase letter. Names starting with an uppercase letter are used for built-in and custom data types (e.g., Math)

Copy link
Author

Choose a reason for hiding this comment

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

Changed this now.

17 changes: 16 additions & 1 deletion 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 @@ -20,3 +20,18 @@ console.log(`The percentage change is ${percentageChange}`);
// d) Identify all the lines that are variable declarations

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?

/*
a) There are 5 at: 1)carPrice = Number(carPrice.replaceAll(",", "")); & 2)priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")),
3) & 4) const priceDifference = carPrice - priceAfterOneYear; 5) const percentageChange = (priceDifference / carPrice) * 100;

b) The error happened due to the missing comma "," in between the 2 parameters/arguments in line 5's function call. Just add a comma to solve
this problem.

c) line 4 & line 5

d) line 1 & line 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 7 and 8 are also declarations, although they are not really "variables".


e) The last expression gets rid of all the commas present in the declared variables in line 1 & 2. or in other words, replaces them commas with
no space between the characters separated by the commas.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you ask ChatGPT to describe the code at line 5, and see if you can use something it suggests in your description?

Copy link
Author

Choose a reason for hiding this comment

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

Done!

*/
13 changes: 12 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 = -10; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -23,3 +23,14 @@ console.log(result);
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer


/*
a) There are 6 in total.
b) 0 function calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

The number of function calls is more than 0.

c) it represents the remainder from the division of movieLength by 60.
d) line 4 represents the total number of mins in the movie (as whole numbers -integers) by getting rid of the decimal parts (in secs).
e) Result represents the total movie duration (in exact hours, exact min and exact sec). movieDuration could be a good name.
f) it works. However, if there's enough time to form a whole hour(s) for example the results shows the total mins and total secs and so
on. So I'd say it works.
Copy link
Contributor

Choose a reason for hiding this comment

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

if there's enough time to form a whole hour(s) for example the results shows the total mins and total secs and so
on.

What do you mean by this statement?

Copy link
Author

Choose a reason for hiding this comment

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

I was basically trying to say that it does work for all movie durations. However, and that depending on the value you may end up with 0 for the hour part and only values for the mins and secs or 0 for both hours and mins and only value for secs for even 0 for all hour, min & sec parts (if movieLength = 0 secs). Anyway, i've rephrased and simplified my response now.

*/
6 changes: 6 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,9 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. ine lines 3-6, penceStringWithoutTrailingP is being declared to get rid of the "p" part of "399p" so that you end up with "399" ONLY.
// 3. Lines 8 paddedPenceNumberString adds "0" to the start of paddedPenceNumberString which is "399" with the aim of it have a total length of 3.
// 4. Lines 9-12, pound is being declared, the value of it aims to extract the "full pounds part" considering 1 pound = 1-- pence.
// 4. Lines 14-16, extract the "pence part" fraction
// 5. Line 18 prints out the sum in pounds and pense.

4 changes: 4 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
// a message with Hello world! message pops up in a small Chrome notification window

Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`.
// small Chrome window pops up with "What is your name?" and underneath it a space for the user to enter and submit their name.

What effect does calling the `prompt` function have?
//prompt expect input from the user by showing a small window with space for input to be submitted once called.
What is the return value of `prompt`?
//undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: To view the return value of a function call, you need to output the return value to the console as console.log( function_call(...) ).

You can also find out exactly what the function returns from the MDN Web Docs website.

8 changes: 7 additions & 1 deletion Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ In this activity, we'll explore some additional concepts that you'll encounter i

Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
What output do you get?
//ƒ log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
// console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
// got 'object' as an output

Answer the following questions:

What does `console` store?
//console doesn't store. it displays.
Copy link
Contributor

Choose a reason for hiding this comment

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

The question is asking what kind of properties are stored in the console object.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
//console.log log or display values to the console. Console.assert, check if a condition is true and in this case no output. Otherwise, an
// error message shows. As for the `,`, it's called the dot notation and it's used to access properties and methods of an object.