Skip to content

Commit 98f2dbe

Browse files
committed
completed sprint 1 exercises
1 parent 3372770 commit 98f2dbe

File tree

12 files changed

+58
-23
lines changed

12 files changed

+58
-23
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ 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+
8+
// Line 3 is reassigning a new value to the 'count' variable.
9+
// In JavaScript, '=' is the assignment operator, not a mathematical equals sign.
10+
// It first evaluates the expression on the right side (count + 1, which is 0 + 1),
11+
// and then assigns that result (1) back to the variable on the left side, updating its value.

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

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ 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 = ;
22-
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = filePath.slice(filePath.lastIndexOf("."));
22+
console.log(`The dir part of ${filePath} is ${dir}`);
23+
console.log(`The ext part of ${filePath} is ${ext}`);
2324
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ 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+
console.log(num);
11+
// Answer: The variable `num` represents a random whole number between 1 and 100 (inclusive).
12+
// Breakdown of the expression:
13+
// 1. Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
14+
// 2. (maximum - minimum + 1) calculates the total number of possible integers in our range (which is 100).
15+
// 3. Multiplying them scales the random decimal to be between 0 and 99.999...
16+
// 4. Math.floor() rounds that decimal down to the nearest whole number (getting an integer from 0 to 99).
17+
// 5. Finally, '+ minimum' shifts the starting point up by 1, resulting in a final integer from 1 to 100.

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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}`);
53
const cityOfBirth = "Bolton";
4+
console.log(`I was born in ${cityOfBirth}`);
5+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
3-
3+
console.log(last4Digits);
44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
66
// Before running the code, make and explain a prediction about why the code won't work

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const time12Hour = "20:53";
2+
const time24Hour = "08:53";
3+
4+
console.log(time12Hour);
5+
console.log(time24Hour);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ 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-
15+
// Answer: There are 5 function calls in total. They are located on lines 4, 5, and 10.
1616
// 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-
17+
// Answer: The error comes from line 5. It occurs because we are trying to reassign a value to `priceAfterOneYear`, which was originally declared as a `const`. To fix it, change `const` to `let` on line 2.
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
// Answer: Lines 4 and 5.
2020
// d) Identify all the lines that are variable declarations
21-
21+
// Answer: Lines 1, 2, 7, and 8.
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
// Answer: It removes the comma from the string using `replaceAll()`, and then converts that cleaned string into a number type using `Number()`. The purpose is to convert a formatted text string into a valid mathematical number so we can do calculations with it later.

0 commit comments

Comments
 (0)