From 2627edd617c2869d0e2413e10d4db4235a41c4c0 Mon Sep 17 00:00:00 2001 From: Poonam Rajput Date: Wed, 2 Sep 2026 16:04:18 +0100 Subject: [PATCH] solution --- Sprint-2/1-key-exercises/1-count.js | 1 + Sprint-2/1-key-exercises/2-initials.js | 13 +++++++++---- Sprint-2/1-key-exercises/3-paths.js | 10 +++++----- Sprint-2/1-key-exercises/4-random.js | 4 ++++ Sprint-2/2-mandatory-errors/0.js | 4 ++-- Sprint-2/2-mandatory-errors/1.js | 2 ++ Sprint-2/2-mandatory-errors/2.js | 2 +- Sprint-2/2-mandatory-errors/3.js | 7 ++++++- Sprint-2/2-mandatory-errors/4.js | 4 ++-- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..3817ae7c5 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ 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 reassigning the existing count variable with the existing value of count incremented by 1 diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..b8e53a4b5 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,10 +1,15 @@ -const firstName = "Creola"; -const middleName = "Katherine"; -const lastName = "Johnson"; +const firstName = 'Creola'; +const middleName = 'Katherine'; +const 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. -const initials = ``; +var firstLetter = firstName[0]; +var secondLetter = middleName[0]; +var thirdLetter = lastName[0]; + +initials = firstLetter + secondLetter + thirdLetter; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..51e64a86b 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -9,15 +9,15 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); +const filePath = '/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt'; +const lastSlashIndex = filePath.lastIndexOf('/'); 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 // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = base.split('.')[1]; -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..cfa8ed1f6 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -3,7 +3,11 @@ 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 + +// Will produce a random number above 1 diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..044add7ac 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..aa6b39ac1 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,5 @@ const age = 33; age = age + 1; + +age = 1; diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..e8410adf7 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +const cityOfBirth = 'Bolton'; console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..b92c6980a 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,14 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = String(cardNumber).slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Before running the code, make and explain a prediction about why the code won't work + +// PREDICTION: won't work because slice is an arr or string method but it's being applied to a int + // Then run the code and see what error it gives. +// type error received + // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..563e0f34d 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = '8:53pm'; +const twentyFourHourClockTime = '20:53';