Skip to content

Commit ec16947

Browse files
committed
rebased sprint 1 solution
1 parent 63c55f5 commit ec16947

File tree

13 files changed

+44
-34
lines changed

13 files changed

+44
-34
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7-
//Line 3 of the code assigns a value to the declared variable count.
8-
// The = sign is an assignment operator, without line 3, the declared variable wil be undefined.
7+
// Line 1 is increasing the count, it is called increment in programming

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ 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 = `${firstName[0]}+${middleName}+${lastName}`;
9-
8+
let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
9+
console.log(initials); //CJK
1010
// https://www.google.com/search?q=get+first+character+of+string+mdn

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ 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,filePath.length-base.length-1) ;
21-
const ext = filePath.slice(-3);
20+
const lastDotIndex = filePath.lastIndexOf(".");
21+
const dir = filePath.slice(0, lastSlashIndex);
22+
const ext = filePath.slice(lastDotIndex + 1);
23+
console.log(dir);
24+
console.log(ext);
2225

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
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
1010

11-
// In the above expression num represent a variable that will store the result of that will be obtained from from the expression.
11+
//In the above expression num represent a variable that will store the result of that will be obtained from from the expression.
1212
// maximum and minimum are variables available on the global scope, as inputs.
1313
// They are evaluated first because of the parenthesis, this gives the precedence
1414
// The output from the parenthesis is now going to serve as the range for the Math.random() method.
1515
// Math.random() method produce random values from 0-1, with 0 and 1 inclusive and exclusive respectively
1616
// The range value makes Math.random() to return result from 0 to range-1
17-
//the Math.floor() methods rounds down the value to the nearest whole number.
18-
// The result from th random operation is added back to the minimum value to return num.
17+
// the Math.floor() methods rounds down the value to the nearest whole number.
18+
// The result from th random operation is added back to the minimum value to return num.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
3-
// JavaScript is single-threaded because it executes tasks in a single flow using a call stack. The function was called before it was declared,
2+
// what's the error ?
3+
// JavaScript is single-threaded because it executes tasks in a single flow using a call stack. The function was called before it was declared,
44
// It was also declared with const, which can not be hoisted to the top, like var.
55
// this result to undefined.
66

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

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let cardNumber = 4533787178994213;
2-
cardNumber=cardNumber.toString();
2+
cardNumber = cardNumber.toString();
33
const last4Digits = cardNumber.slice(-4);
44

55
// The last4Digits variable should store the last 4 digits of cardNumber
@@ -9,6 +9,11 @@ const last4Digits = cardNumber.slice(-4);
99
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
1010
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
1111

12+
// The last4Digits variable should store the last 4 digits of cardNumber
13+
// Then run the code and see what error it gives.
14+
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
15+
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
16+
1217
// The variable cardNumber is a number data type, numbers do not have slice methods or function, only string does.
1318
//TypeError: cardNumber.slice is not a function
14-
// Yes, it gives what i predicted
19+
// Yes, it gives what i predicted

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const twelveHourClockTime = "20:53";
2-
const twentyFourHourClockTime = "08:53";
2+
const twentyFourHourClockTime = "08:53";

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ console.log(`The percentage change is ${percentageChange}`);
1919
// 3. line 10 console.log() that logs the result to the console
2020

2121
// 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?
22-
// The error in this code is coming from line 5. The wrong use of the
23-
// replaceAll method without a comma between the pattern and replacement in the function argument.
22+
// The error in this code is coming from line 5. The wrong use of the replaceAll syntax without a separator in the function arguments.
2423
// I will fix this problem by reading the documentation, to see the right way the syntax should be written.
2524
//Then i will add the comma where necessary
26-
2725
// c) Identify all the lines that are variable reassignment statements
28-
// line 4 and 5 are variable reassignment
26+
// line 4 and 5 are variable reassignment
2927

3028
// d) Identify all the lines that are variable declarations
31-
// line 1,2,7,8 are all variable declaration
29+
// line 1,2,7,8 are all variable declaration
3230

3331
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34-
// this expression replaces the comma at the string with an empty string and the convert the string data type to a number data type
32+
// this expression replaces the comma at the string with an empty string and the convert the string data type to a number data type

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
1010
console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
13-
1413
// a) How many variable declarations are there in this program?
1514
// there are 6 variable declaration.
1615

16+
1717
// b) How many function calls are there?
1818
// One function call
1919

@@ -28,8 +28,7 @@ console.log(result);
2828

2929
// e) What do you think the variable result represents? Can you think of a better name for this variable?
3030
// the variable result represent total movie duration in hours,minute and seconds.
31-
// const=movieDuration
32-
31+
// const=runningTime
3332
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34-
// this code works for all movie length and integer values.
35-
// for movie length which are multiples of 60 it returns hours with 0 minutes and 0 seconds
33+
// this code works for all movie running time and integer values.
34+
// for movie running time which are multiples of 60 it returns hours with 0 minutes and 0 seconds

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ const penceStringWithoutTrailingP = penceString.substring(
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);
9+
const pounds = paddedPenceNumberString.substring(
10+
0,
11+
paddedPenceNumberString.length - 2
12+
);
1013

11-
const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
14+
const pence = paddedPenceNumberString
15+
.substring(paddedPenceNumberString.length - 2)
16+
.padEnd(2, "0");
1217

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

@@ -27,5 +32,4 @@ console.log(`£${pounds}.${pence}`);
2732
// from every length character of the padded string
2833
// 5.const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0");: This expression add '0' to the end if the paddedString is not
2934
// upto 2 characters
30-
// 6. this line is a function call to log the argument inside it to the console. it use template literals to get the values of the variables
31-
35+
// // 6. this line is a function call to log the argument inside it to the console. it use template literals to get the values of the variables

0 commit comments

Comments
 (0)