Skip to content

Commit edcff8e

Browse files
author
Enice-Codes
committed
completed js excercises
1 parent de0d814 commit edcff8e

8 files changed

Lines changed: 31 additions & 15 deletions

File tree

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ let count = 0;
22

33
count = count + 1;
44

5+
56
// Line 3 reassigns the value of count.
7+
// count = 0 +1 ;
8+
// count = 1
9+
610
// The expression on the right side (count + 1) is evaluated first using the current value of count.
711
// The = assignment operator then stores the result back into the count variable, replacing its previous value.
812

913

1014
// Line 1 is a variablbe declaration, creating the count variable with an initial value of 0
1115
// Describe what line 3 is doing, in particular focus on what = is doing
16+
// In line 3 the = operator assigns a new value to the variable count.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ let lastName = "Johnson";
77

88
let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
99

10+
1011
// https://www.google.com/search?q=get+first+character+of+string+mdn

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const base = filePath.slice(lastSlashIndex + 1);
1414
console.log(`The base part of ${filePath} is ${base}`);
1515

1616
// Create a variable to store the dir part of the filePath variable
17-
// Create a variable to store the ext part of the variable
1817

1918
const dir = filePath.slice (0,lastSlashIndex);
19+
20+
// Create a variable to store the ext part of the variable
21+
2022
const ext = base.slice(base.lastIndexOf(".") + 1);
2123

2224
// https://www.google.com/search?q=slice+mdn
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
const minimum = 1;
2-
const maximum = 100;
1+
const minimum = 3;
2+
const maximum = 50;
33

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

66
// In this exercise, you will need to work out what num represents?
7+
// the num is random number between 1 and 100.
78
// Try breaking down the expression and using documentation to explain what it means
8-
9-
//num is a random number between 1 and 100
9+
// const minimum is a function expression
10+
// = 1 is a minimum value assigned by the operator for the minimum
11+
// = 100 is the maximum value assigned by the operator for the function.
1012

1113
// Method.floor generates a random number between 0 and 1 to nearest interger (whole number)
1214
//Math.random generates a decimal number between 0 and 1 .
1315

1416
// It will help to think about the order in which expressions are evaluated
1517
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1618
console.log(num);
19+
// I noticed that the different values change the print result .

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
This is just an instruction for the first activity - but it is just for human consumption
22
We don't want the computer to run these 2 lines - how can we solve this problem?
33

4-
// we can use //to comment out the lines of code we don't want to run.
54

65
//his is just an instruction for the first activity - but it is just for human consumption
7-
//We don't want the computer to run these 2 lines - how can we solve this problem?
6+
//We don't want the computer to run these 2 lines - how can we solve this problem?
7+
8+
// we can use //to comment out the lines of code we don't want to run.

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

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

33
let age = 33;
4-
age = age + 1;
4+
age = 33 + 1;
55
console.log(age);

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ const last4Digits = String(cardNumber).slice(-4);
66
console.log(last4Digits); // "4213"
77

88

9-
let prediction = " because of the lack of slice method available for numbers,I predict that the code will throw an error. the cardNumber variable is a number, and slice is a method that can only be used on strings or arrays.";
10-
slice is a method that can only be used on strings or arrays."
9+
//.slice () works on arrays and strings
1110

12-
//.slice () works on arrays and strings
1311

14-
// i ran the code the error i got was excatly as predicted.
15-
16-
// The last4Digits variable should store the last 4 digits of cardNumber
1712
// However, the code isn't working
1813
// Before running the code, make and explain a prediction about why the code won't work
1914
// Then run the code and see what error it gives.
15+
// I ran the code the error i got was excatly as predicted.
16+
17+
2018
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
19+
// let prediction = " because of the lack of slice method available for numbers,I predict that the code will throw an error.
20+
// the cardNumber variable is a number, and slice is a method that can only be used on strings or arrays.";
21+
//slice is a method that can only be used on strings or arrays." //
22+
2123
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
24+
25+
// The last4Digits variable should store the last 4 digits of cardNumber
26+
console.log(last4Digits); // "4213"

0 commit comments

Comments
 (0)