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 24 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: line 3 shows increment operation - 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.
*/

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
8 changes: 8 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,11 @@ 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. Since Math.random() returns an integer in the interval [0, 1). This means num eventually represents any random integer in the interval [0, 100].
2. Math.floor() rounds down the expression "Math.random() * (maximum - minimum + 1)"", leading to an integer in the interval [0,100).

3. So num returns an integer in the interval [0,100) + 1 which eventually means num return [0, 100]
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 clockTime24Hour = "20:53";
const clockTime12Hour = "08:53";
16 changes: 15 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,17 @@ 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) lines 1, 2, 7 & 8

e) Firstly, it removes all commas in the string and eventually converts the new string into a number.
*/
12 changes: 11 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 = 0; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -23,3 +23,13 @@ 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) Only one function call "console.log(result)".
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) Yes, It does work when trying different values of movieLength.
*/
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`?
//a string - the name entered my the user.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you were writing a program that uses prompt() to ask for an input value, how can
your program tell if the user clicked "OK" or "Cancel"?

Copy link
Author

Choose a reason for hiding this comment

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

when clicking ok it displays a string if the user entered a value otherwise, it leads to an empty string. when clicking cancel it displays null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Both console.log("null") and console.log(null) can result in null appearing in the console.
Instead of focusing on the console output, it's clearer to explain what prompt() actually returns.

Copy link
Author

Choose a reason for hiding this comment

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

To be honest, I don't know how to answer this apart from the fact that when ok clicked the user's input is returned otherwise in cancellation null is returned.

Copy link
Contributor

Choose a reason for hiding this comment

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

The term "display" in your original comment suggested you are referring to the values output by console.log() in the console.

Returns is the standard technical term for what a function "generates". It aligns with programming language terminology.

Your latest description is correct.

when ok is clicked the user's input is returned otherwise in cancellation null is returned

Copy link
Author

Choose a reason for hiding this comment

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

Thanks CJ!

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?
//it stores different logging, debugging, warning/errors and information properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these logging, debugging, ... properties? Are they numbers, strings, or ....?

Copy link
Author

Choose a reason for hiding this comment

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

They are indeed properties - Pairs of keys and their corresponding values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Saying "console is an object that stores ... properties" is too vague; it doesn't explain what kind of properties they are or what they do. Are they storing numbers, strings, or something else? It would be more helpful to clarify what these properties actually represent. Can you provide more detail about them?

Copy link
Author

Choose a reason for hiding this comment

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

Done. Hopefully, my response is sufficient now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Describing code can be quite challenging at first (even in your native language).
Knowing the proper terminologies is important.
That's why I keep suggesting using ChatGPT to explore alternative ways to describe code. Along the way, you might also pick up some useful programming terminology.

Copy link
Author

Choose a reason for hiding this comment

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

Noted. Really appreciate your feedback :)

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.