Skip to content

London | May-2025 | Reza Jahanimir | Sprint-1 #489

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 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4537db5
tried to explain variable redeclaration
Reza-Jahanimir Jun 7, 2025
2c8408a
leaned how to use string formatting
Reza-Jahanimir Jun 7, 2025
e07fba5
learned slice,lastIndexOf and how can we use them together for slice
Reza-Jahanimir Jun 7, 2025
b5673e8
explained num represents
Reza-Jahanimir Jun 7, 2025
f946b02
make a comment
Reza-Jahanimir Jun 7, 2025
e7ba13d
understanding const and let
Reza-Jahanimir Jun 7, 2025
0def05a
understating how does system reads the coder
Reza-Jahanimir Jun 7, 2025
6421e9f
string method
Reza-Jahanimir Jun 7, 2025
87d44eb
string methods
Reza-Jahanimir Jun 7, 2025
259306e
learn about Variable Naming Rules
Reza-Jahanimir Jun 7, 2025
be72b0d
answered the questions
Reza-Jahanimir Jun 7, 2025
b47e499
answered the questions
Reza-Jahanimir Jun 7, 2025
cf581dd
explained the code line by line
Reza-Jahanimir Jun 7, 2025
3999f62
learned what is v8 and node.js
Reza-Jahanimir Jun 7, 2025
d314a95
a short view of object oriented languages. what is a object and how c…
Reza-Jahanimir Jun 7, 2025
078e279
cleaned up the code style
Reza-Jahanimir Jun 19, 2025
54f716e
describe output, purpose
Reza-Jahanimir Jun 19, 2025
f7e6a17
change the number to a string
Reza-Jahanimir Jun 19, 2025
72c375f
answered all the questions
Reza-Jahanimir Jun 19, 2025
1d85b48
changed the variable called result
Reza-Jahanimir Jun 19, 2025
73cc423
try the alert function, possible values we get from prompt
Reza-Jahanimir Jun 19, 2025
77b600c
fixed the code
Reza-Jahanimir Jun 20, 2025
637cd50
use a toString()method
Reza-Jahanimir Jun 22, 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
3 changes: 3 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,6 @@ 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

// We are updating the previous value of count to a new value. The = operator assigns a new value
// to the variable, meaning the data stored in memory is being changed.
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]}`;

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

console.log(initials);
16 changes: 7 additions & 9 deletions Sprint-1/1-key-exercises/3-paths.js

Choose a reason for hiding this comment

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

Good solution, but can you see any places here where you could clean up the code style?

Choose a reason for hiding this comment

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

This looks much neater - especially having all the logs together

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

// (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}`);
const lastDotIndex = filePath.lastIndexOf(".");

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
const base = filePath.slice(lastSlashIndex + 1); // file.txt
const dir = filePath.slice(0, lastSlashIndex); // /Users/mitch/cyf/Module-JS1/week-1/interpret
const ext = filePath.slice(lastDotIndex); // .txt

const dir = ;
const ext = ;

// https://www.google.com/search?q=slice+mdn
console.log(`Base part of path: ${base}`);
console.log(`Dir part of path: ${dir}`);
console.log(`Ext part of path: ${ext}`);
18 changes: 18 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js

Choose a reason for hiding this comment

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

You've identified correctly what each of the math operations is doing. Can you describe what the overall purpose of the line is? What will the output of num be?

Choose a reason for hiding this comment

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

Great explanation

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ 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


// order of math calculation - () > ** > * / % > + - (Parentheses first, then Exponentiation
// (right to left), then Multiplication/Division/Modulo (left to right), then Addition/Subtraction
// (left to right)).

//Math.floor - returns the value of x rounded down to its nearest integer
//Math.random - returns a random number

// First, the innermost parentheses are evaluated: (maximum - minimum + 1).
// Then, the result is multiplied by the random number generated by the Math object.
// Math.floor rounds the result down to the nearest integer.
// Finally, the value is added to the minimum.

// the purpose - To generate a random whole number between minimum and maximum, inclusive.
// output - It will be a random integer between 1 and 100.
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 sole this by witting these two as comments
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;

// we have to use let as it allows the value to be reassign
12 changes: 11 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// 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}`);
// the system reads the code top to bottom and because the variable has been create/define before
// the consol.log it can not recognize the variable

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

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


31 changes: 22 additions & 9 deletions Sprint-1/2-mandatory-errors/3.js

Choose a reason for hiding this comment

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

You are correct that .slice() is a string method. With that in mind, what changes could you make to this code to fix the problem?

Choose a reason for hiding this comment

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

This works in this case. Would this still work if the number was being passed as a parameter?

Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
const cardNumber = 4533787178994213;
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
// result as a string
let cardNumber = 4533787178994213;
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits); // Output: "4213"


// result as a number
const last4DigitsNum = Number(cardNumber.toString().slice(-4));
console.log(last4DigitsNum); // Output: 4213


// the function your asked return string
function last4DigitsStr(cardNumber) {
const last4Digs= cardNumber.toString().slice(-4);
return last4Digs;
}

// the function your asked return number
function last4DigitsNum(number) {
const last4Digs= Number(number.toString().slice(-4));
return last4Digs;
}
17 changes: 15 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.

Why are you talking about "Go" variable naming rules here?

Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const HourClockTime24 = "20:53";
const hourClockTime12 = "08:53";

// Go Variable Naming Rules
// A variable can have a short name (like x and y) or a more descriptive name (age, price, carname, etc.).

// Go variable naming rules:

// A variable name must start with a letter or an underscore character (_)
// A variable name cannot start with a digit
// A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
// Variable names are case-sensitive (age, Age and AGE are three different variables)
// There is no limit on the length of the variable name
// A variable name cannot contain spaces
// The variable name cannot be any Go keywords
33 changes: 32 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 found 2 function calls correctly, can you see any others?
b) You have found a fix for the problem - can you explain why the original line would not work?
c) good answer
d) Correct, the first 2 lines are declarations. Are those the only declarations in this code?
e) Good explanation of what the functions do. can you explain why we want to convert it into an integer?

Choose a reason for hiding this comment

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

Very good answers

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,42 @@ 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
// Function calls:
// Line 4 - .replaceAll, Number
// Line 5 - .replaceAll, Number
// Line 10 - 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?
// from line :5
// fix: add , - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
// Why is the original line causing an error?
// We were trying to subtract two string values like "30000" - "24000" but
// In JavaScript, strings with commas (like "24,000") can’t be parsed directly to numbers
// So this fails



// c) Identify all the lines that are variable reassignment statements
// line 4 , 5



// d) Identify all the lines that are variable declarations
// lines : 1 , 2 , 7 , 8
// Line 1: let carPrice
// Line 2: let priceAfterOneYear
// Line 6: const priceDifference
// Line 7: const percentageChange



// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// method replaceAll is changing a specific character and replace it with the one we asked for.
// function number which changes a string number value to integers.
// purpose : is to have a integer instead of a string

// explain why we want to convert it into an integer?
// We use Number(carPrice.replaceAll(",", "")) to convert a formatted string into a real number,
// so we can do mathematical calculations on it.
18 changes: 15 additions & 3 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.

Good answers for most of these.
e) The result will be a formatted string, but the question is asking if there might be a better name for it than simply "result" - can you think of one?

Choose a reason for hiding this comment

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

Good suggestions

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ const totalMinutes = (movieLength - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;

const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(result);
const formattedTime = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(totalMinutes);

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

// b) How many function calls are there?
// 1

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// The % operator (modulo) returns the remainder of a division.
// In this case, it returns how many seconds are left after dividing the total seconds by 60.
// For example, 8784 % 60 = 24 — so 24 seconds remain.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// we are calculating the total minutes.
// we subtract movieLength by remainingSeconds because remaining seconds don't add up to a full min.
// convert to minute by dividing by 60.

// e) What do you think the variable result represents? Can you think of a better name for this variable?

// The variable `result` represents the movie's length in a time format: `HH:MM:SS`.
// string format
// better name can be `formattedTime` or `HHMMSS`
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Yes, the code works for all non-negative values of `movieLength`, including 0.
// However, for values less than 60, it will return 0 hours and 0 minutes
21 changes: 20 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,23 @@ 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);
// .substring - selects a section between the given indexes in a string -> "399", by doing this we remove the "p"

// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// The padStart() method pads penceStringWithoutTrailingP with another string (multiple times) until it reaches a given length 3.
// id we have a one digit number it adds two "004" but if the number is 3 digits will keep it as it is "399"

// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
// Extracts the pound portion, which is the first part of the 3-digit string -> "3"

// 5. const pence = paddedPenceNumberString
// .substring(paddedPenceNumberString.length - 2)
// .padEnd(2, "0");
// it is two separate parts
// first - with substring method we select the two last digits
// second - ensures that if somehow only one digit is returned it’s padded to two characters by adding a "0" to the end.

// 6. Displays the formatted price in British pounds -> £3.99 or £0.05
10 changes: 10 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md

Choose a reason for hiding this comment

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

  1. Did you also try the alert function?
  2. Are there any other possible values you could get from prompt? Think about what other interactions might the user have with the popup box.

Choose a reason for hiding this comment

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

Good work investigating these functions

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
-It causes the browser to display a modal popup box with the message "Hello world!"
-It blocks interaction with the page until the user clicks "OK"
-It returns undefined — the purpose is only to notify, not to receive input.

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`.
const myName = prompt("What is your name?");


What effect does calling the `prompt` function have?
browser displays a popup dialog box

What is the return value of `prompt`?
A string - if the user types something and clicks OK
An empty string ("") - if they click OK but type nothing
null - if the user clicks Cancel
18 changes: 18 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,30 @@ 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?
ƒ 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`
typeof(console);
'object'

Answer the following questions:

What does `console` store?
console is a built-in JavaScript object provided by browsers (like Chrome, Firefox, etc.). It stores a collection of functions that help developers log, debug, and inspect values during runtime.
It doesn’t store data like a variable; instead, it holds methods (a.k.a. functions) like:
console.log() – print to the console
console.error() – print errors
console.warn() – print warnings
console.assert() – test if an expression is true

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
- `console.log` or `console.assert`
These are method calls on the console object.
You're telling JavaScript: "Use the log or assert method that belongs to the console object."
- the `.` mean
The dot (.) is the member access operator in JavaScript.
It accesses a property or method of an object