diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..7661d75c53 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ 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 a statement. Here we reassign the value of count from 0 to 1 by adding value one to it \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..10cc52f0ab 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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.charAt(0)+middleName.charAt(0)+lastName.charAt(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..1e9adc0328 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,9 +15,21 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +function dirString(){ + const dirName = filePath.slice(1,lastSlashIndex); + return dirName; +} + // Create a variable to store the ext part of the variable +function extString(){ + const lastDotIndex = filePath.lastIndexOf("."); + const extName = filePath.slice(lastDotIndex); + return extName; +} -const dir = ; -const ext = ; +const dir = dirString(filePath); +const ext = extString(filePath); +console.log(dir); +console.log(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..d8fd5d4bb7 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,9 +1,18 @@ const minimum = 1; const maximum = 100; - const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +console.log(num); // In this exercise, you will need to work out what num represents? // 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 + +//In the declaration of num, we can break it down to below: + +//1. A randon number, which is with decimals between 0 and 1, is created by method Math.random() +//2. The random number in step 1 is multipled by 100. That makes an number with decimals. +//3. The method Math.floor grounded the number in step 2 down to a whole number between 0 - 99. +//4. The number from step 3 is added 1, so it makes a whole number between 1-100. + +//I think the overall javascript code here is to make a random whole number between 1-100. \ No newline at end of file