diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..87856f6a4f 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,13 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +/*Line 3 is updating the value of the variable `count`. +The `=` operator is an assignment operator, +which means it takes the value on the right side +(in this case, `count + 1`) +and assigns it to the variable on the left side (`count`). +So, it takes the current value of `count`, adds 1 to it, +and then stores that new value back into `count`. +in general, Line 3 is incrementing the value of `count` by 1. +*/ + diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..0a1e1535c0 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; - +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..8864e5ff77 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,8 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; - +const dir = filePath.slice(0,lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".")); +console.log (`The directory is : ${dir} +The extension is : ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..2204d16132 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -4,6 +4,15 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // In this exercise, you will need to work out what num represents? + // num represents a random integer between 1 and 100. // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + // breaking down the expression into smaller parts. +/* Math.floor(): this will return the largest integer less than or equal to a given number. In this case, it will round down the result of the expression inside the parentheses. +Math.random(): this will return a random floating-point number between 0 (inclusive) and 1 (exclusive). In this case, it will generate a random number between 0 and 1 but never exactly 1. +(maximum - minimum + 1): this will calculate the range of numbers we want to generate. In this case, it will calculate the difference between the maximum and minimum values (100 - 1 = 99) +and add 1 to include both endpoints (99 + 1 = 100). +finally, the code adds the minimum value (which is 1) to the result. +*/ +