Skip to content

Commit 95ef210

Browse files
committed
corrected issues identified by the reviewer
1 parent 22e0557 commit 95ef210

7 files changed

Lines changed: 31 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
const firstName = "Creola";
22
const middleName = "Katherine";
33
const lastName = "Johnson";
4-
// const initial = "initials";
5-
// const index = 1;
64

7-
// console.log('The ${Initial} ${index} is ${firstName.charAt(index)}');
8-
// Declare a variable called initials that stores the first character of each string.
5+
96
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
107

118
const initials = firstName[0] + middleName[0] + lastName[0];

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
// (0.68 * 100 ) + 1
6+
console.log(num)
57

68
// In this exercise, you will need to work out what num represents?
79
// Try breaking down the expression and using documentation to explain what it means
@@ -10,4 +12,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1012

1113
// Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition
1214
// I used 0.68 for math.floor(random number) + 1
13-
// Sum = 69
15+
// Sum = 69
16+
// 1.num represents a number which is an Integer that is greater or equal to 1
17+
// 2.start by (maximum-minimum +1) which the output is 100
18+
// 3.math.random()*100 returns random number between 0 and 100. Any random number less that 1 can be selected then multiplied by 100
19+
// 4.math.floor() gives out the largest integer which is less than or equal to the given number which is a decimal
20+
// The output is displayed in console log

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

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

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;
55

6-
console.log(age)
6+
console.log(age);
77

88
// The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice.
9-
// This case, I have used let instead in order to allow the variable to be reused.
9+
// This case, I have used let instead in order to allow the variable to be reused.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
3+
console.log(last4Digits);
34

45
// The last4Digits variable should store the last 4 digits of cardNumber
56
// However, the code isn't working
@@ -11,4 +12,4 @@ const last4Digits = cardNumber.slice(-4);
1112
//Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file
1213
// Error returned: TypeError: cardNumber.slice is not a function
1314
// Lesson learnt here; slice method is only available for strings or arrays not numbers
14-
// So converted the cardNumber into a string first
15+
// So converted the cardNumber into a string first

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

Lines changed: 7 additions & 5 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,12 +12,14 @@ 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-
// 2
16-
//carPrice = Number(carPrice.replaceAll(",", ""));
17-
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ","));
15+
// 5
16+
// * number() and .replaceAll() in line 4
17+
// * number() and .replaceAll()in line 4
18+
// console.log()
1819
// 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?
1920
//b) error = SyntaxError: missing ) after argument list
2021
// (",", ",")); - added , between quoted values
22+
// The error was coming from line 5 due to a missing comma in the replaceAll() method
2123
// c) Identify all the lines that are variable reassignment statements
2224
//carPrice = Number(carPrice.replaceAll(",", ""));
2325
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ","));
@@ -27,4 +29,4 @@ console.log(`The percentage change is ${percentageChange}`);
2729
//const priceDifference = carPrice - priceAfterOneYear;
2830
//const percentageChange = (priceDifference / carPrice) * 100;
2931
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
30-
// e) cleans the amount format by removing characters such as , and leaving only number
32+
// e) cleans the amount format by removing characters such as , and leaving only number

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ console.log(result);
1515
// 6 variables
1616

1717
// b) How many function calls are there?
18-
// 2
18+
// 1 (console.log())
1919
// c) Using documentation, explain what the expression movieLength % 60 represents
2020
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2121
// It means 60 % remainder of Movie length
22+
// 24 seconds
2223

2324
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
2425
// totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60;
26+
//it means changing the value that was in second into minute by dividing it 60 - making it a whole number
2527

2628
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2729
// I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet
30+
// It represents the MovieDuration
2831

2932
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
3033
//any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ 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
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString
@@ -26,7 +26,9 @@ console.log(`£${pounds}.${pence}`);
2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
2828
// 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39
29+
// 2. P will be dropped
2930
// 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399
3031
// 4 const pounds - removes 2 characters from the amount = 3
3132
// 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99
32-
// 6. console displays the figures in pounds and pence = 3.99
33+
// 5. const pence is initialised in 2 methods 1)extracts the string from index 2)adds 0 hence = 99
34+
// 6. console displays the figures in pounds and pence = 3.99

0 commit comments

Comments
 (0)