Skip to content

LONDON_JAN25 | KHALIL ALI | STRUCTURING_AND_TESTING_DATA | SPRINT 1 | WEEK 4 #446

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 4 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
5 changes: 5 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,8 @@ 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 reassignment for the variable count.
we start from the right hand part so 0 + 1 = 1
the " = " in line 3 means assigning the right hand part to the left hand var.
count = 1 ;
*/
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

7 changes: 5 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,10 @@ 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(0, lastSlashIndex)
const ext = filePath.slice(lastSlashIndex + 5)
Copy link

Choose a reason for hiding this comment

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

Can you modify your approach for extracting the file extension so that it can work for "name" and the "extension" of any length? For example, index.html, 3-paths.js.


console.log("dir :", dir)
console.log("ext :", ext)

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

console.log("num value is :", num)
/*
Math.random():returns a random number between n = [ 0 , 1 [ .
Copy link

Choose a reason for hiding this comment

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

The typical interval notation to represent 0 to 1, including 0 but excluding 1 is, [0, 1).

Math.floor() :returns the previous real number of a decimal number .
Copy link

Choose a reason for hiding this comment

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

This description does not make much sense.
For example, 3.14 is also a real number.
Can you rephrase it, or ask ChatGPT or looking the MDN reference of Math.floor()?

num = Math.floor (n*(100 - 1 + 1) + 1 ;
num = Math.floor (n*100 + 1)
num = Math.floor (100n + 1)

num range between : [ 1 , 100 ]
num range between : [ minimum , maximum ]

*/
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
/*
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?
*/

/*
* to add a comment you have two options :
1- // add one line comment
2- /*add multiline comment */
4 changes: 4 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,7 @@

const age = 33;
age = age + 1;

/*
to define a variable with reassign feature you should use `let` instead of `const`
*/
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

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


/*code is rendered line by line.
* so you should define the variable cityOfBirth first
* then you can use it
*/
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
Comment on lines +1 to 2
Copy link

Choose a reason for hiding this comment

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

Can you use an approach that does not involve replacing the original value?


// The last4Digits variable should store the last 4 digits of cardNumber
Expand All @@ -7,3 +7,8 @@ const last4Digits = cardNumber.slice(-4);
// 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
console.log(last4Digits)

/*slice() is a function takes only string array as an argument.
* thats why we changed cardNumber
*/
8 changes: 6 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const HourClockTime24 = "20:53";
const hourClockTime12 = "08:53";

Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

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

Why start one variable name in lowercase letter and the other one with uppercase letter?

/*variables names can not start with a number.
*
*/
8 changes: 7 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,9 @@ 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) 3 times . lines (4,5,10)
Copy link

Choose a reason for hiding this comment

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

There are more than 3 function calls. Can you identify all of them?

// b) line 5 . syntax error in replaceAll function. add comma
// c) 4 , 5 lines
// d) 1 , 2 , 7 , 8 lines
// e) replace each "," in carPrice with nothing which means : delete each comma
Copy link

Choose a reason for hiding this comment

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

This only described the priceAfterOneYear.replaceAll("," ,"") part of the expression, and not the whole expression.

7 changes: 7 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ 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) 6 times
// b) 1 time
// c) the reminder after applying division (movieLength / 60) which equals to 24
// d) number of minutes in movieLength
// e) movieDuration
// f) yes it will work for all real positive values of movieLength
19 changes: 8 additions & 11 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");

console.log(`£${pounds}.${pence}`);

Expand All @@ -25,3 +17,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 3. substring() : cuts a part of the whole string. in this line we remove "p" from penceString.
// 5. padStart() : add character to a string. in this line we check the string length is three,if not we add "0" to the start
// 6. accounts the number of pounds which is 3
// 8. accounts the number of pounds which is 99. in this line we check the string length is two,if not we add "0" to the start
// 10. 3.99