Skip to content

Commit c861b14

Browse files
applying Prittier formating for the files
1 parent 5a76622 commit c861b14

11 files changed

Lines changed: 83 additions & 103 deletions

File tree

‎Sprint-2/1-key-exercises/2-initials.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ const firstName = "Creola";
22
const middleName = "Katherine";
33
const lastName = "Johnson";
44

5-
6-
75
// Declare a variable called initials that stores the first character of each string.
86
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
97

10-
const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`
8+
const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;
119

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

14-
15-
console.log(initials)
12+
console.log(initials);

‎Sprint-2/1-key-exercises/3-paths.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = filePath.slice(0,lastSlashIndex);
21-
/*correction : slice(0,lastSlashIndex); is the correct method to extract the dir path
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
/*correction : slice(0,lastSlashIndex); is the correct method to extract the dir path
2222
filePath.slice(start, end) => 0 represents the character 0 of the filePath String put 1 will skip the first charchter.
2323
*/
2424

25-
26-
const ext = filePath.slice(filePath.lastIndexOf(".")+1);
25+
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);
2726

2827
// https://www.google.com/search?q=slice+mdn
2928

3029
console.log(`The dir part of the filePath ${filePath}variable is ${dir}`);
3130

3231
console.log(`The ext part of a variable file.txt is ${ext}`);
33-

‎Sprint-2/1-key-exercises/4-random.js‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1010

1111
console.log(num);
1212

13-
//First operation
13+
//First operation
1414
// num is generating a random dicimal number with method Math.random() between 0 and 1 result eg :0.3948605
1515

16-
17-
1816
//Second operation
1917
//The generated number is multiplied by the range+1 which is between 1-100 result eg 39.48605
2018

19+
//Third operation
20+
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
2121

22-
//Third operation
23-
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
24-
25-
26-
27-
// Last operation is to add the "minimum" (in this case it's 1 or it can be changed to any changed number e.g 10) this will shift the random number so it starts counting from minimum, instead of from zero.
28-
//eg . num was 39 => 40
22+
// Last operation is to add the "minimum" (in this case it's 1 or it can be changed to any changed number e.g 10) this will shift the random number so it starts counting from minimum, instead of from zero.
23+
//eg . num was 39 => 40

‎Sprint-2/2-mandatory-errors/0.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/*This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?*/
2+
We don't want the computer to run these 2 lines - how can we solve this problem?*/

‎Sprint-2/2-mandatory-errors/1.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Answer : The Error is : TypeError: Assignment to constant variable.
88
Constants in JavaScript can't be reassigned to correct this we have to change the varible type from const => let.
99
1010
*/
11-
console.log(age)
11+
console.log(age);

‎Sprint-2/2-mandatory-errors/2.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// what's the error ?
33

44
//Answer : the error was that CitOfBirth vaiable was declared after the method cosole .log()
5-
//The solution is to declare it before calling it.
5+
//The solution is to declare it before calling it.
66

77
const cityOfBirth = "Bolton";
88

99
console.log(`I was born in ${cityOfBirth}`);
10-

‎Sprint-2/2-mandatory-errors/3.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ cardNumber.toString()
1818
1919
*/
2020

21-
console.log(last4Digits);
21+
console.log(last4Digits);

‎Sprint-2/3-mandatory-interpret/1-percentage-change.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16-
1716
/*
1817
Solution to a)
1918
@@ -29,7 +28,6 @@ There are 5 function calls in this file:
2928
3029
*/
3130

32-
3331
// 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?
3432
/*
3533
Solution to b)
@@ -64,4 +62,3 @@ The expresssion Number(carPrice.replaceAll(",","")) is removing the comma "," in
6462
in String type , removing the comma will insure the mathimatical operation will go normal when converted to type Number.
6563
6664
*/
67-

‎Sprint-2/3-mandatory-interpret/2-time-format.js‎

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,56 @@ console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
1313

14-
15-
1614
// a) How many variable declarations are there in this program?
1715
/************************************************** */
1816
/* Solution a): There are 6 varibale declarations */
1917
/************************************************* */
2018

21-
2219
// b) How many function calls are there?
23-
/**************************************************/
24-
/* Solution b): */
25-
/* There is only one fuction call (console.log() */
26-
/*********************************************** */
20+
/**************************************************/
21+
/* Solution b): */
22+
/* There is only one fuction call (console.log() */
23+
/*********************************************** */
2724

2825
// c) Using documentation, explain what the expression movieLength % 60 represents
2926
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
3027

3128
/*********************************************************************************************************************/
3229
/*Solution c): */
33-
/* The operator (%) called Modulo returns the remainder left over when one operand is divided by a second operand */
34-
/* In this expamle it gives the time remainder of the movie in seconds */
30+
/* The operator (%) called Modulo returns the remainder left over when one operand is divided by a second operand */
31+
/* In this expamle it gives the time remainder of the movie in seconds */
3532
/*********************************************************************************************************************/
3633

37-
38-
3934
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
4035

41-
/****************************************************************************************************************************************************************************/
42-
/* Solution d): */
43-
/* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
44-
/* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
45-
/* This way we have the Movie total exact number of miutes. */
46-
/****************************************************************************************************************************************************************************/
47-
36+
/****************************************************************************************************************************************************************************/
37+
/* Solution d): */
38+
/* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
39+
/* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
40+
/* This way we have the Movie total exact number of miutes. */
41+
/****************************************************************************************************************************************************************************/
4842

4943
// e) What do you think the variable result represents? Can you think of a better name for this variable?
50-
/*********************************************************************************************/
51-
/* Solution e): */
52-
/* The variable result represents the exact lenght of the movie in Hours + Minutes + Seconds */
53-
/* A better name for variable result could be : extctMovieLength */
54-
/*********************************************************************************************/
44+
/*********************************************************************************************/
45+
/* Solution e): */
46+
/* The variable result represents the exact lenght of the movie in Hours + Minutes + Seconds */
47+
/* A better name for variable result could be : extctMovieLength */
48+
/*********************************************************************************************/
5549

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

5852
/***************************************************************************************************************************************************************/
59-
/* Solution e): */
60-
/* movieLength = 0 => exactMovieLength = 0:0:0 */
61-
/* movieLength = 60 => exactMovieLength = 0:1:0 */
62-
/* movieLength = 3676 => exactMovieLength = 1:1:16 */
63-
/* movieLength = -3600 => exactMoveLenght = -1:0:0 */
64-
/* movieLength = 90000 => exactMoveLenght = 25:0:0 */
65-
/* */
66-
/* This code Could be better: */
67-
/* - giving a negative value for movieLength will result in a negative clock: so there could have message that reject negative numbers. */
68-
/* - The program should have represented Hours/Min/Sec in this format 00:00:00 so each time should be represented with 2 digits. */
69-
/* - 25 hours exeeds 24 hours which represents a day so a variable total days could be added to represent time in days. */
70-
/* -Values with dicimal numbers will return the clock showing dicimal numbers this should be rounded up or down to the nearst time with an integer number */
71-
/* */
72-
/**********************************************************************************************************************************************************/
73-
53+
/* Solution e): */
54+
/* movieLength = 0 => exactMovieLength = 0:0:0 */
55+
/* movieLength = 60 => exactMovieLength = 0:1:0 */
56+
/* movieLength = 3676 => exactMovieLength = 1:1:16 */
57+
/* movieLength = -3600 => exactMoveLenght = -1:0:0 */
58+
/* movieLength = 90000 => exactMoveLenght = 25:0:0 */
59+
/* */
60+
/* This code Could be better: */
61+
/* - giving a negative value for movieLength will result in a negative clock: so there could have message that reject negative numbers. */
62+
/* - The program should have represented Hours/Min/Sec in this format 00:00:00 so each time should be represented with 2 digits. */
63+
/* - 25 hours exeeds 24 hours which represents a day so a variable total days could be added to represent time in days. */
64+
/* -Values with dicimal numbers will return the clock showing dicimal numbers this should be rounded up or down to the nearst time with an integer number */
65+
/* */
66+
/**********************************************************************************************************************************************************/

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99

10-
const pounds = paddedPenceNumberString.substring( 0,
11-
paddedPenceNumberString.length - 2
10+
const pounds = paddedPenceNumberString.substring(
11+
0,
12+
paddedPenceNumberString.length - 2,
1213
);
13-
console.log(pounds)
14+
console.log(pounds);
1415

1516
const pence = paddedPenceNumberString
1617
.substring(paddedPenceNumberString.length - 2)
@@ -27,7 +28,7 @@ console.log(`£${pounds}.${pence}`);
2728
// To begin, we can start with
2829
// 1. const penceString = "399p": initialises a string variable with the value "399p"
2930
// 2. penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): This line of code slice the penceString varible by removing the "p" character from it.
30-
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will confert it to "022".
31+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will convert it to "022".
3132
// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); : This line of code extract and store the value of pound from paddedPenceNumberString using the substring method since £1 = 100 pences => any number in the hudered position i.e third character from the right onwards has a value of £.
3233
// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0");: This line of code extract and store the value of pences paddedPenceNumberString using the substring method => instead of starting from the left it start from the right moving two positions then it adds "0"in case the pences value is less then 10.
33-
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in $ and pences in nice readable way => £3.99
34+
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in £ and pences in nice readable way => £3.99

0 commit comments

Comments
 (0)