Skip to content

Commit 1c7d558

Browse files
committed
sprint1 solutions
1 parent 3372770 commit 1c7d558

File tree

14 files changed

+81
-21
lines changed

14 files changed

+81
-21
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ 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.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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 = ``;
8+
let initials = `${firstName[0]}+${middleName}+${lastName}`;
99

1010
// https://www.google.com/search?q=get+first+character+of+string+mdn
11-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 = ;
21-
const ext = ;
20+
const dir =filePath.slice(0,filePath.length-base.length-1) ;
21+
const ext = filePath.slice(-3);
2222

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ 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+
11+
// In the above expression num represent a variable that will store the result of that will be obtained from from the expression.
12+
// maximum and minimum are variables available on the global scope, as inputs.
13+
// They are evaluated first because of the parenthesis, this gives the precedence
14+
// The output from the parenthesis is now going to serve as the range for the Math.random() method.
15+
// Math.random() method produce random values from 0-1, with 0 and 1 inclusive and exclusive respectively
16+
// 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.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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?
1+
//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?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
// what's the error ?
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,
4+
// It was also declared with const, which can not be hoisted to the top, like var.
5+
// this result to undefined.
36

4-
console.log(`I was born in ${cityOfBirth}`);
57
const cityOfBirth = "Bolton";
8+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const cardNumber = 4533787178994213;
1+
let cardNumber = 4533787178994213;
2+
cardNumber=cardNumber.toString();
23
const last4Digits = cardNumber.slice(-4);
34

45
// The last4Digits variable should store the last 4 digits of cardNumber
@@ -7,3 +8,7 @@ const last4Digits = cardNumber.slice(-4);
78
// Then run the code and see what error it gives.
89
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
910
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
11+
12+
// The variable cardNumber is a number data type, numbers do not have slice methods or function, only string does.
13+
//TypeError: cardNumber.slice is not a function
14+
// Yes, it gives what i predicted

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const twelveHourClockTime = "20:53";
2+
const twentyFourHourClockTime = "08:53";

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

Lines changed: 12 additions & 1 deletion
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;
@@ -13,10 +13,21 @@ 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+
//There are 5 function call in this code.
17+
// 1. Line 4 has 2 function call, .replaceAll() and Number()
18+
//2. Line 5 ditto line 4
19+
// 3. line 10 console.log() that logs the result to the console
20+
1621
// 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 replaceAll syntax without a separator.
23+
// I will fix this problem by reading the documentation, to see the right way the syntax should be written.
24+
//Then i will add the comma where necessary
1725

1826
// c) Identify all the lines that are variable reassignment statements
27+
// line 4 and 5 are variable reassignment
1928

2029
// d) Identify all the lines that are variable declarations
30+
// line 1,2,7,8 are all variable declaration
2131

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

0 commit comments

Comments
 (0)