Skip to content

Commit f738b2f

Browse files
committed
fixed feedback mistakes
1 parent 4f047d6 commit f738b2f

12 files changed

Lines changed: 89 additions & 63 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ count = count + 1;
88

99

1010

11-
Line 1 is a declaration and Line 3 is a statement that changes the value of the variable 'count' by adding 1 to its current value.
12-
The variable is changing from 0 to 1 after line 3 is executed after we used 'let' to declare the variable 'count' and then we used the = operator to assign the new value.
11+
//Line 1 is a declaration and Line 3 is a statement that changes the value of the variable 'count' by adding 1 to its current value.
12+
//The variable is changing from 0 to 1 after line 3 is executed after we used 'let' to declare the variable 'count' and then we used the = operator to assign the new value.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ console.log(`The base part of ${filePath} is ${base}`);
1919

2020
const dir = filePath.slice(0, lastSlashIndex);
2121

22+
const ext = base.slice(base.lastIndexOf("."));
23+
24+
25+
console.log(dir);
26+
console.log(ext);
2227

23-
const ext = base.slice(45);
2428

2529

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

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ console.log(num);
1111
// It will help to think about the order in which expressions are evaluated
1212
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1313

14-
Num represents a random whole number between the value of 'minimum' (1) and 'maximum' (100)
15-
By creating a constant variable called 'num' and assigning it the value of the expression, we can generate a random number within the mentioned range.
16-
17-
When running the program we have to understand how the expression works:
18-
19-
we have to work out the parentheses first, maximum - minimum + 1, which is equal to 100 - 1 + 1 = 100.
20-
so: Math.floor(Math.random() *100) + 1
21-
Math.random() produces a pseudo-random decimal number that is greater than or equal to 0 but less than 1.
22-
23-
Next, we need to multiply the result from Math.random() by 100. This may give us the result of a decimal between 0 and 100.
24-
Next step is to use Math.floor() wich then rounds down the decimal number to the nearest whole integer. This then means that the result will be a whole number between 0 and 99.
25-
But we want 1-100, so we add 1 to the result of Math.floor() this then changes the range to be inclusive of 1 and 100.
26-
After adding 1, we need to round down the number to the nearest interger, this is done by using Math.floor(). After this we will have a whole number between maximum and minimum.
27-
Therefore, the final result of num will be a random whole number between 1 and 100, inclusive.
14+
//Num represents a random whole number between the value of 'minimum' (1) and 'maximum' (100)
15+
//By creating a constant variable called 'num' and assigning it the value of the expression, we can generate a random number within the mentioned range.
16+
17+
//When running the program we have to understand how the expression works:
18+
19+
//we have to work out the parentheses first, maximum - minimum + 1, which is equal to 100 - 1 + 1 = 100.
20+
//so: Math.floor(Math.random() *100) + 1
21+
// Math.floor is used 1 time and it happens before + minimum. Math.floor is used because when used Math.random() it produces a decimal number between 0 and 1.
22+
//The code needs a whole number because we are trying to get a number between 1 and 100, this is where Math.floor comes () comes in and removes the decimal part.
23+
//JavaScript works out the expression inside Math.floor () first before + minimum.
24+
//Math.random() produces a pseudo-random decimal number that is greater than or equal to 0 but less than 1.
25+
26+
//Next, we need to multiply the result from Math.random() by 100. This may give us the result of a decimal between 0 and 100.
27+
//Next step is to use Math.floor() wich then rounds down the decimal number to the nearest whole integer. This then means that the result will be a whole number between 0 and 99.
28+
//But we want 1-100, so we add 1 to the result of Math.floor() this then changes the range to be inclusive of 1 and 100.
29+
//After adding 1, we need to round down the number to the nearest interger, this is done by using Math.floor(). After this we will have a whole number between maximum and minimum.
30+
//Therefore, the final result of num will be a random whole number between 1 and 100, inclusive.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't
1+
//This is just an instruction for the first activity - but it is just for human consumption
2+
//We don't
3+
34
// want the computer to run these 2 lines - how can we solve this problem?
45

5-
We can add 2 forward slashes , by typing two forward slashes ( // ) at the beginning of the line, we can turn that line into a comment. This then means that the computer will completely ignore that line and not run it.
6+
//We can add 2 forward slashes , by typing two forward slashes ( // ) at the beginning of the line, we can turn both lines into a comment. This then means that the computer will completely ignore that line and not run it.
67

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ console.log (age);
66

77

88

9-
const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.
10-
This is because we cannot change the value of a constant variable once we have created it.
9+
//const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.
10+
//This is because we cannot change the value of a constant variable once we have created it.
1111

12-
If we want to change the value of age, we need to use let instead of consts when declaring the variable. this then allows us to reassign the value of age by adding 1 to it.
12+
//If we want to change the value of age, we need to use let instead of consts when declaring the variable. this then allows us to reassign the value of age by adding 1 to it.
1313

1414

1515

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

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

4-
error
4+
//error
55

6-
console.log(`I was born in ${cityOfBirth}`);
7-
const cityOfBirth = "Bolton";
6+
//console.log(`I was born in ${cityOfBirth}`);
7+
//const cityOfBirth = "Bolton";
88

9-
The reason there is an error is because we are using the wrong order, we are telling Javascript to print the value of cityOfBirth before creating a variable.
10-
So we need to create the variable first, this is because Javascript runs code from top to bottom, so a variable that is declared with const needs to be declared before using it.
9+
//The reason there is an error is because we are using the wrong order, we are telling Javascript to print the value of cityOfBirth before creating a variable.
10+
//So we need to create the variable first, this is because Javascript runs code from top to bottom, so a variable that is declared with const needs to be declared before using it.
1111

1212

1313

14-
right way
14+
//right way
1515

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

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ const last4Digits = cardNumber.slice(-4);
1111

1212
console.log(last4Digits);
1313

14-
I think that Javascript will give an error because .slice() is normally used with strings, and cardNumber is currently a number.
15-
const cardNumber = 4533787178994213; does not have any quotation marks, so Javascript will treat it as a number.
14+
//I think that Javascript will give an error because .slice() is normally used with strings, and cardNumber is currently a number.
15+
//const cardNumber = 4533787178994213; does not have any quotation marks, so Javascript will treat it as a number.
1616

17-
When run with console.log(last4Digits); we get --> TypeError : cardNumber.slice is not a function
17+
//When run with console.log(last4Digits); we get --> TypeError : cardNumber.slice is not a function
1818

19-
.slice is a method used with strings and we need to make cardNumber into a string by adding quotation marks.I
19+
//.slice is a method used with strings and we need to make cardNumber into a string by adding quotation marks.I
2020

21-
const cardNumber = 4533787178994213 to const cardNumber = "4533787178994213";
22-
Now cardNumber is a string, then we can re run the code with console.log(last4Digits); to get the correct code.
21+
//we can change the expression by making it intoa string by doing --> const last4Digits = String(cardnumber).slice(-4);
22+
//String(cardNumber) changes the number into a string and .slice(-4) takes the last 4 characters and stores it in last4Digits.
23+
//const cardNumber = 4533787178994213 to const cardNumber = "4533787178994213";
24+
//Now cardNumber is a string, then we can re run the code with console.log(last4Digits); to get the correct code.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ console.log(hour24ClockTime);
99

1010

1111

12-
Variable names cannot start with a number as Javascript doesnt allow it, it can contan number inside the variable but not at the beginning.
12+
//Variable names cannot start with a number as Javascript doesn't allow it, it can contain a number inside the variable but not at the beginning.

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

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

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,13 +12,19 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
There are 5 function calls, two function calls on line 4 = Number(...) and replaceAll(...) two more on line 5 = Number(...) and replaceAll(...) and finally on line 10 = console.log(...)
15+
//>
16+
// There are 5 function calls, two function calls on line 4 = Number(...) and replaceAll(...) two more on line 5 = Number(...) and replaceAll(...) and finally on line 10 = console.log(...)
17+
1618
// 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-
SyntaxError: missing a comma to separate the arguments
19+
20+
//>SyntaxError: missing a comma to separate the arguments
21+
1822
// c) Identify all the lines that are variable reassignment statements
19-
carPrice = Number(carPrice.replaceAll(",", "")); and priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
23+
//>carPrice = Number(carPrice.replaceAll(",", "")); and priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
24+
2025
// d) Identify all the lines that are variable declarations
21-
There are 4 variable declarations- 1) let carPrice = "10,000"; 2) let priceAfterOneYear = "8,543";
22-
3) const priceDifference = carPrice-priceAfterOneYear; 4) const percentageChange = (priceDifferenc/carPrice)* 100;
26+
//>There are 4 variable declarations- 1) let carPrice = "10,000"; 2) let priceAfterOneYear = "8,543";
27+
//3) const priceDifference = carPrice-priceAfterOneYear; 4) const percentageChange = (priceDifferenc/carPrice)* 100;
28+
2329
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
24-
Number(carPrice.replaceAll(",", "")); is a string and the expression removes the comma from "10,000" and converts "10000" from a string into the number 10000.
30+
//>Number(carPrice.replaceAll(",", "")); is a string and the expression removes the comma from "10,000" and converts "10000" from a string into the number 10000.
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 90.5; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,20 +12,29 @@ 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-
6 variable Declarations, every const creates a new variable.
15+
//>6 variable Declarations, every const creates a new variable.
16+
1617
// b) How many function calls are there?
17-
1 function calls is console.log() as it is a function being called and told to do the job
18+
//>1 function calls is console.log() as it is a function being called and told to do the job
19+
1820
// c) Using documentation, explain what the expression movieLength % 60 represents
1921
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2022

21-
movieLength % 60 means finding the remainder after dividing movieLength by 60. movieLength = 8784 so we need to do: 8784 % 60 = 146.4 and the nearest whole integer is 146.
22-
So there are 146 complete groups of 60. we then multiply; 146 x 60= 8760 --> 8784 - 8760 = 24 so 8784 % 60 = 24 and therefore remainingSeconds becomes 24.
23+
//>movieLength % 60 means finding the remainder after dividing movieLength by 60. movieLength = 8784 so we need to do: 8784 % 60 = 146.4 and the nearest whole integer is 146.
24+
//So there are 146 complete groups of 60. we then multiply; 146 x 60= 8760 --> 8784 - 8760 = 24 so 8784 % 60 = 24 and therefore remainingSeconds becomes 24.
25+
//8784/60 = 146.4. and 8784 % 60 = 24 as this is the remainder.
2326

2427
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25-
const totalMinutes = (movieLength - remainingSeconds) / 60 ---> if we break it down -> movieLength = 8784 remainingSeconds = 24
26-
we then subtract remainingSeconds from movieLength= 8784 -24 = 8670. we then have to divide it by 60 which gives us 8760 / 60 = 146. we divide because there is 60 seconds in one minute, and right now we are converting seconds into minutes.
28+
//>const totalMinutes = (movieLength - remainingSeconds) / 60 ---> if we break it down -> movieLength = 8784 remainingSeconds = 24
29+
//we then subtract remainingSeconds from movieLength= 8784 -24 = 8670. we then have to divide it by 60 which gives us 8760 / 60 = 146. we divide because there is 60 seconds in one minute, and right now we are converting seconds into minutes.
30+
2731
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28-
The result variable will show us he complete results from our calculations of = totalHours:remainingMinutes:remainingSeconds.
29-
result = 2:26:24
32+
//>The result variable will show us he complete results from our calculations of = totalHours:remainingMinutes:remainingSeconds.
33+
//result = 2:26:24
34+
3035
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31-
I tested differnet codes: 7965 and I got the result 2:12:45 and i also tried : 2654 and got 0:44:14.
36+
//>I tested differnet codes: 7965 and I got the result 2:12:45 and i also tried : 2654 and got 0:44:14.
37+
38+
//> suggestions to run code - 59 gives us 0:0:59 > less than 60 seconds
39+
//-90 gives us 0:-1:-30 - not valid as the code works properly for non-negative whole numbers
40+
//90.5 gives us 0:1:30.5 > this tells us 60 goes into 90.5 once and 30.5 is the remainder

0 commit comments

Comments
 (0)