From 4e8d29562855c8194ba9e120c49d822feb5d83eb Mon Sep 17 00:00:00 2001 From: Said Akbarov <134784793+FrenchFry36@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:25:02 +0200 Subject: [PATCH 1/3] errors resolved --- week-1/errors/0.js | 4 ++-- week-1/errors/1.js | 4 +++- week-1/errors/2.js | 2 +- week-1/errors/3.js | 4 +++- week-1/errors/4.js | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/week-1/errors/0.js b/week-1/errors/0.js index cf6c5039..044add7a 100644 --- a/week-1/errors/0.js +++ b/week-1/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/week-1/errors/1.js b/week-1/errors/1.js index 7a43cbea..72a74282 100644 --- a/week-1/errors/1.js +++ b/week-1/errors/1.js @@ -1,4 +1,6 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +var age = 33; age = age + 1; + +console.log(age); diff --git a/week-1/errors/2.js b/week-1/errors/2.js index e09b8983..2865eb8a 100644 --- a/week-1/errors/2.js +++ b/week-1/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 ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); diff --git a/week-1/errors/3.js b/week-1/errors/3.js index ffa72ca4..80841ac0 100644 --- a/week-1/errors/3.js +++ b/week-1/errors/3.js @@ -1,5 +1,7 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working diff --git a/week-1/errors/4.js b/week-1/errors/4.js index 21dad8c5..f1f9bb8b 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const a12HourClockTime = "20:53"; +const a24hourClockTime = "08:53"; From d211d12d6196dbad90963fa63e19d349b94d7518 Mon Sep 17 00:00:00 2001 From: Said Akbarov <134784793+FrenchFry36@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:29:20 +0200 Subject: [PATCH 2/3] exercises resolved --- week-1/exercises/count.js | 2 +- week-1/exercises/decimal.js | 7 ++++++- week-1/exercises/initials.js | 5 +++++ week-1/exercises/paths.js | 7 +++++++ week-1/exercises/random.js | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/week-1/exercises/count.js b/week-1/exercises/count.js index 117bcb2b..026507b0 100644 --- a/week-1/exercises/count.js +++ b/week-1/exercises/count.js @@ -1,6 +1,6 @@ let count = 0; -count = count + 1; +count = count + 1; // reassigned // 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 diff --git a/week-1/exercises/decimal.js b/week-1/exercises/decimal.js index bd4a4740..dd57cb71 100644 --- a/week-1/exercises/decimal.js +++ b/week-1/exercises/decimal.js @@ -1,6 +1,11 @@ - const num = 56.5467; +const wholeNumberPart = Math.floor(num); +const decimalPart = parseFloat((num - wholeNumberPart).toFixed(4)); +const roundedNum = Math.round(num); +console.log(wholeNumberPart); +console.log(decimalPart); +console.log(roundedNum); // You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index 50b62103..2249b660 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -1,6 +1,11 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; +let initials = `${firstName.slice(0, 1)}${middleName.slice( + 0, + 1 +)}${lastName.slice(0, 1)}`; +console.log(initials); // Declare a variable called initials that stores the first character of each string in upper case to form the user's initials // Log the variable in each case diff --git a/week-1/exercises/paths.js b/week-1/exercises/paths.js index c91cd2ab..d064662d 100644 --- a/week-1/exercises/paths.js +++ b/week-1/exercises/paths.js @@ -16,3 +16,10 @@ 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 = filePath.slice(0, lastSlashIndex); +console.log(`The dir part of ${filePath} is ${dir}`); + +const lastDotIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDotIndex); +console.log(`The ext part of ${filePath} is ${ext}`); diff --git a/week-1/exercises/random.js b/week-1/exercises/random.js index 79a4a4d5..c0d0bbee 100644 --- a/week-1/exercises/random.js +++ b/week-1/exercises/random.js @@ -2,6 +2,7 @@ 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 From a2c8602c548065f7c6ef94b321ba22c1445b4914 Mon Sep 17 00:00:00 2001 From: Said Akbarov <134784793+FrenchFry36@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:44:44 +0200 Subject: [PATCH 3/3] interpret resolved --- week-1/interpret/percentage-change.js | 4 ++++ week-1/interpret/time-format.js | 5 +++++ week-1/interpret/to-pounds.js | 12 ++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/week-1/interpret/percentage-change.js b/week-1/interpret/percentage-change.js index 49b0ac15..fa3cf3eb 100644 --- a/week-1/interpret/percentage-change.js +++ b/week-1/interpret/percentage-change.js @@ -12,9 +12,13 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made +// - 4,5,10 // b) Identify all the lines that are variable reassignment statements +// - 4, 5 // c) Identify all the lines that are variable declarations +// - 1, 2, 7, 8 // d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// - turns the value of the variable to the number data type and returns its value with elimination the comma diff --git a/week-1/interpret/time-format.js b/week-1/interpret/time-format.js index 7961fe0d..08d93ca0 100644 --- a/week-1/interpret/time-format.js +++ b/week-1/interpret/time-format.js @@ -14,14 +14,19 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// - 7 // b) How many function calls are there? +// - 1 // c) Using documentation on MDN, explain what the expression movieLength % 60 represents +// - divides value of it by 60 and returns the remainder // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// - it counts the integer that could be divided by 60 without reminder // e) What do you think the variable result represents? Can you think of a better name for this variable? +// - its represents the movie length in hours, minutes and seconds. A better name for this variable is movieDuration // f) Think about whether this program will work for all values of movieLength. // Think of what values may cause problems for the code. diff --git a/week-1/interpret/to-pounds.js b/week-1/interpret/to-pounds.js index 196be3b2..bc07d501 100644 --- a/week-1/interpret/to-pounds.js +++ b/week-1/interpret/to-pounds.js @@ -3,17 +3,17 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 -); +); // 399 -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // 399 const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 -); +); // 3 const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + .padEnd(2, "0"); // 99 console.log(`£${pounds}.${pence}`); @@ -27,3 +27,7 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP penceString.substring(0, penceString.length - 1): returns numeric part of value +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): adds "0" before given value for the length of 3 digits +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): returns the part of string between begin and 1 digit - "3" +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): gets the first digit of number and adds "00" at the end