Skip to content

Commit 37da673

Browse files
committed
sprint-1 exercies has been completed
1 parent 8f3d6cf commit 37da673

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

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+
let initials = `${firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0)}`;
9+
console.log(typeof(initials)) //==> CKJ
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
1515
console.log(`The base part of ${filePath} is ${base}`);
1616

17+
1718
// Create a variable to store the dir part of the filePath variable
1819
// Create a variable to store the ext part of the variable
1920

20-
const dir = ;
21-
const ext = ;
21+
const dir = filePath.slice(0,lastSlashIndex)
22+
23+
const lastDoutIndex = base.lastIndexOf(".")
24+
const ext = base.slice(lastDoutIndex)
25+
console.log(ext)
2226

2327
// https://www.google.com/search?q=slice+mdn
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const minimum = 1;
22
const maximum = 100;
33

4-
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
4+
const num = Math.floor(0.999 * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
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+
console.log(num)
11+
//num is a random number between the minimum and maximum.
12+
// 1. Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1
13+
// 2. (maximum - minimum + 1) Calculates the range of values, including both ends.
14+
// For 1 to 100, this is:
15+
// 100 - 1 + 1 = 100
16+
//3- Math.floor() static method always rounds down and returns the largest integer less than or equal to a given number.
17+
// example Math.floor(50.9) = 50

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+
// const age = 33;
4+
let age = 33;
45
age = age + 1;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
4-
console.log(`I was born in ${cityOfBirth}`);
3+
// console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
// Variables declared with (const) (or let) are not accessible before their declaration, even though they are hoisted (set aside in memory).
7+
// // So, when console.log(...) runs, cityOfBirth exists in memory but is not yet initialized, so trying to access it throws an error.

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
3-
41
// The last4Digits variable should store the last 4 digits of cardNumber
52
// However, the code isn't working
63
// Before running the code, make and explain a prediction about why the code won't work
74
// Then run the code and see what error it gives.
85
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
96
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
7+
// .slice() called on a number, and Numbers don’t have string methods like .slice().it will throw an error
8+
// console.log(last4Digits) => TypeError: cardNumber.slice is not a function at Object.
9+
const cardNumber = 4533787178994213;
10+
// const last4Digits = cardNumber.toString;
11+
const last4Digits = cardNumber % 10000;
12+
console.log(last4Digits)

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 12HourClockTime = "20:53";
2+
// const 24hourClockTime = "08:53";
3+
// JavaScript does not allow variable names to begin with a digit. The variable name 12HourClockTime starts with 12,
4+
// which is not valid syntax, and will throw a SyntaxError:
5+
6+
const hourClockTime24 = "20:53";
7+
const hourClockTime12 = "08:53";

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

Lines changed: 2 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;
@@ -12,6 +12,7 @@ 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+
// 3 functions in lines 4, 5 and 10
1516

1617
// 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?
1718

0 commit comments

Comments
 (0)