Skip to content

Commit 69c8b16

Browse files
committed
Glasgow | 26-ITP-Jan| Fattouma Ouannassi | Sprint 2 | coursework
<!-- You must title your PR like this: Region | Cohort | FirstName LastName | Sprint | Assignment Title For example, London | 25-ITP-May | Carol Owen | Sprint 1 | Alarm Clock Fill in the template below - remove any sections that don't apply. Complete the self checklist - replace each empty box in the checklist [ ] with a [x]. Add the label "Needs Review" and you will get review. Respond to volunteer reviews until the volunteer marks it as "Complete". Please note: if the PR template is not filled as described above, an automatic GitHub bot will give feedback in the "Conversation" tab of the pull request and not allow the "Needs Review" label to be added until it's fixed. --> ## Learners, PR Template Self checklist - [x] I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title - [x] My changes meet the requirements of the task - [x] I have tested my changes - [x] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/reviewing/style-guide/) ## Changelist Sprint 2 directory: This project focuses on learning how to use JavaScript methods. Questions. ## Questions /
1 parent 124ae45 commit 69c8b16

11 files changed

Lines changed: 64 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ let lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

8-
let initials = ``;
8+
const initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
9+
console.log( `acronym = ${initials}`);
910

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

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
1615

1716
// Create a variable to store the dir part of the filePath variable
1817
// Create a variable to store the ext part of the variable
1918

20-
const dir = ;
21-
const ext = ;
19+
const lastDot = filePath.lastIndexOf(".");
20+
console.log(`The indexDot is ${lastDot}`);
21+
22+
const ext = filePath.slice(lastDot);
23+
24+
const fileName = filePath.slice(lastSlashIndex + 1, lastDot);
25+
const dir = filePath.slice(1, lastSlashIndex + 1);
26+
27+
28+
29+
console.log(`The dir is -> ${dir}`);
30+
console.log(`The nameFile is -> ${fileName}`);
31+
console.log(`The extension is -> ${ext}`);
2232

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
Math.floor() //removes decimal part and returns whole number
11+
Math.random() //needs to values between minimum and maximum to generate a random number
12+
console.log(maximum - minimum + 1 ) + minimum; // this is same as 100 - 1 + 1 = 100
13+
console.log(`The random number is ${num}`);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33; // I to used 'let' to reassign a variable
44
age = age + 1;
5+
console.log(age);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
// The variable cityOfBirth has to be before the console.log statement.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const numberString = cardNumber.toString(); // We have to convert the cardNumber to a string first before slicing the last 4 digits.
3+
const last4Digits = numberString.slice(-4);
4+
const num = Number(last4Digits);
5+
6+
console.log(num);
37

48
// The last4Digits variable should store the last 4 digits of cardNumber
59
// However, the code isn't working

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const T12HourClockTime = "20:53";
2+
const T24hourClockTime = "08:53";
3+
console.log (T12HourClockTime);
4+
console.log (T24hourClockTime);
5+
/*const 12HourClockTime = "20:53";
6+
const 24hourClockTime = "08:53";
7+
JS variable names (identifiers) must not start with a digit only start with a letter*/
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

4-
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
4+
carPrice = Number(carPrice.replaceAll(",",""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
99

1010
console.log(`The percentage change is ${percentageChange}`);
1111

1212
// Read the code and then answer the questions below
13-
1413
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
14+
// There are 3 function (lines 4,5, and 10)
1615
// 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?
17-
16+
// line 5, the replaceAll method is missing a comma between its arguments.
1817
// c) Identify all the lines that are variable reassignment statements
19-
18+
// 4 and 5)
2019
// d) Identify all the lines that are variable declarations
21-
20+
// 1, 2, 7, and 8
2221
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
22+
/*The expression Number(carPrice.replaceAll(",", "")) first removes the commas from the string value of carPrice.
23+
After that, it converts the cleaned string into a number.
24+
The purpose is to make sure the value can be used in mathematical calculations.*/

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15-
15+
// There are 6 variable
1616
// b) How many function calls are there?
17-
17+
// There is 1 function call in the program: console.log(result)
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
19+
// The expression movieLength % 60 calculates the remainder when movieLength is divided by 60.
1920
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2021

2122
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
23+
// This line removes the leftover seconds from the total movie length and then divides the result by 60 to convert the remaining time into whole minutes.
2324
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
25+
// The variable result stores the movie length formatted
2526
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
27+
// The code will work correctly for positive whole numbers representing seconds.

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
const penceString = "399p";
2-
2+
// initialises a string variable with the value "399p"
33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7-
7+
// Removes the final character ("p") from the string, leaving only the numeric part of the price.
88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
1111
paddedPenceNumberString.length - 2
1212
);
13-
13+
// Ensures the string has at least three characters by adding leading zeros if necessary.
1414
const pence = paddedPenceNumberString
1515
.substring(paddedPenceNumberString.length - 2)
1616
.padEnd(2, "0");
17+
//Takes the last two digits as the pence part and ensures it is exactly two characters long.
18+
1719

1820
console.log(${pounds}.${pence}`);
21+
// Combines the pounds and pence into a formatted currency string and outputs the final result in pounds (£)
1922

2023
// This program takes a string representing a price in pence
2124
// The program then builds up a string representing the price in pounds

0 commit comments

Comments
 (0)