From 0fd575d86a375a3b7a564165c659496a54fea903 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Wed, 30 Oct 2024 00:41:33 +0000 Subject: [PATCH 01/25] done 1.js --- Sprint-1/errors/0.js | 4 ++-- Sprint-1/errors/1.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-1/errors/0.js b/Sprint-1/errors/0.js index cf6c5039f..6a7a7f690 100644 --- a/Sprint-1/errors/0.js +++ b/Sprint-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? \ No newline at end of file diff --git a/Sprint-1/errors/1.js b/Sprint-1/errors/1.js index 7a43cbea7..90b05f16f 100644 --- a/Sprint-1/errors/1.js +++ b/Sprint-1/errors/1.js @@ -1,4 +1,13 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +// to run this file we need to go in the root and once we are in the file run, node 1.js eg => /Sprint-1/errors node 1.js + +cost age = 33; // this line is not working because const does not allow you change the data so we can change to let. age = age + 1; +console.log(age); + + +let age = 33; +age = age + 1; +console.log(age); + From b9595e1bb2d1dcaa01d93495907046da5e4ed54a Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 31 Oct 2024 23:32:31 +0000 Subject: [PATCH 02/25] done errors 2.js --- Sprint-1/errors/0.js | 5 ++++- Sprint-1/errors/1.js | 10 ++++++---- Sprint-1/errors/2.js | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Sprint-1/errors/0.js b/Sprint-1/errors/0.js index 6a7a7f690..db8fc82c8 100644 --- a/Sprint-1/errors/0.js +++ b/Sprint-1/errors/0.js @@ -1,2 +1,5 @@ // 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 +// We don't want the computer to run these 2 lines - how can we solve this problem? + +// To make a multi-line comment in JavaScript, you can start with /* and end with */ . Any text +// in between will be considered a comment and will not be executed as code by the computer. diff --git a/Sprint-1/errors/1.js b/Sprint-1/errors/1.js index 90b05f16f..6aeb04a6f 100644 --- a/Sprint-1/errors/1.js +++ b/Sprint-1/errors/1.js @@ -1,10 +1,12 @@ // trying to create an age variable and then reassign the value by 1 -// to run this file we need to go in the root and once we are in the file run, node 1.js eg => /Sprint-1/errors node 1.js +// to run this file we need to go in the root and once we are in the file run, node 1.js eg => cd /Sprint-1/errors => ~ node 1.js -cost age = 33; // this line is not working because const does not allow you change the data so we can change to let. -age = age + 1; -console.log(age); + +// this line is not working because const does not allow you change the data so we can change to let. +// cost age. = 33; +// age = age + 1; +// console.log(age); let age = 33; diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..82b9be40f 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -1,5 +1,9 @@ // 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}`); + +// we just need to move the console.log() to avoid render and expression which was calling the data declared in the variable +//ReferenceError: Cannot access 'cityOfBirth' before initialization \ No newline at end of file From 049285a421007a0d31eb09ad2526f63d9522bd8d Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 1 Nov 2024 00:03:23 +0000 Subject: [PATCH 03/25] done error 3.js --- Sprint-1/errors/3.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..58602de5b 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,5 +1,3 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +5,24 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // 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 + + +// const cardNumber = 4533787178994213; +// const last4Digits = cardNumber.(-4); + +// console.log(last4Digits); + + + +// String.prototype.slice() +// The slice() method of String values extracts a section of this string and returns it as a new string, +// without modifying the original string. but in this example we have number we can extract this. +// 1 slice work only with String +// 2 we have to convert the variable to String +// 3 Option we can just added a single quotation but this variable is saving number. + + +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); + +console.log(last4Digits); \ No newline at end of file From b401696be6ee06a6075e27d2161ca2dd6d7ef877 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 1 Nov 2024 00:36:56 +0000 Subject: [PATCH 04/25] done error 4.js --- Sprint-1/errors/4.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..f5c15070f 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,12 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// const 12HourClockTime = "20:53"; +// const 24hourClockTime = "08:53"; + +// this is given an error because we can no start an variable with number So we can fix moving the number +// in the middle or we can write the number instead declare the integer number + +const hour12ClockTime = "20:53"; +console.log(hour12ClockTime); + + +const hour24ClockTime = "08:53"; +console.log(hour24ClockTime); \ No newline at end of file From 9facd61317e893f167957e4ddb0bd893ae84c6c4 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 1 Nov 2024 00:48:14 +0000 Subject: [PATCH 05/25] done exercises count.js --- Sprint-1/exercises/count.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..b65fc3c30 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -1,6 +1,10 @@ +// 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 + let count = 0; count = count + 1; +console.log(count); + +// line 3 is taking the first value and reassings this new value to count its value + the number 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 From 45eab066e423af9d1bffcac8b1fea55f4ae74463 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 1 Nov 2024 00:52:29 +0000 Subject: [PATCH 06/25] done exercises count.js --- Sprint-1/exercises/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index b65fc3c30..fddaf1fe8 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -6,5 +6,5 @@ let count = 0; count = count + 1; console.log(count); -// line 3 is taking the first value and reassings this new value to count its value + the number 1 +// line 3 is taking the first value and reassigns this new value to count its value + the number 1 From bcff93955a1eae54b4dbc91d592bd54eb5cf416b Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Fri, 1 Nov 2024 20:32:45 +0000 Subject: [PATCH 07/25] done exercises decimal.js --- Sprint-1/exercises/decimal.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..99de61fce 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -3,7 +3,26 @@ const num = 56.5678; // 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 ) + + const wholeNumberPart = (Math.floor(num)); + + // Create a variable called decimalPart and assign to it an expression that evaluates to 0.5678 ( the decimal part of num ) + +// parseFloat() picks the longest substring starting from the beginning that generates a valid +// number literal. If it encounters an invalid character, it returns the number represented up +// to that point, ignoring the invalid character and all characters following it. +// If the argument's first character can't start a legal number literal per the syntax above, +// parseFloat returns NaN. + + const decimalPart = parseFloat((num - wholeNumberPart).toFixed(4)); + + // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) + + const roundedNum = (Math.round(num)); + // Log your variables to the console to check your answers +console.log(wholeNumberPart, decimalPart, roundedNum); + From 1f01abe0d8e9a054512c962a45e2fba984def26b Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 2 Nov 2024 00:05:51 +0000 Subject: [PATCH 08/25] done exercises paths.js --- Sprint-1/exercises/paths.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index c91cd2ab3..f92a45576 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -9,10 +9,28 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) +/* ================ lastIndexOf() =================== +-we use this to obtain the last position of / where is located the File.txt +-const base = filePath.slice(lastSlashIndex + 1); with + 1 we start to subtract after / +Index: 0 1 2 ... 37 38 39 40 41 42 +filePath: / U s ... / f i l e .txt +- +*/ + const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); +console.log(lastSlashIndex); // 44 const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); +console.log(base); // file.txt +// 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 lastDotIndex = filePath.lastIndexOf("."); +console.log(lastDotIndex); // index position 49 +const extractDir = filePath.slice(0, lastDotIndex); +console.log(`Directory and filename (without extension) ${extractDir}`); + + +// Create a variable to store the ext part of the variable" +const extensionName = filePath.slice(lastDotIndex + 1); +console.log(`extension: ${extensionName}`); // txt From 71340157ff8e0c99bfc8d52039a590c3d7c774a4 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 7 Nov 2024 23:38:48 +0000 Subject: [PATCH 09/25] adding a function on random.js to check the result --- Sprint-1/exercises/paths.js | 2 +- Sprint-1/exercises/random.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index f92a45576..cbe9916c4 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -28,7 +28,7 @@ console.log(base); // file.txt const lastDotIndex = filePath.lastIndexOf("."); console.log(lastDotIndex); // index position 49 const extractDir = filePath.slice(0, lastDotIndex); -console.log(`Directory and filename (without extension) ${extractDir}`); +console.log(`Directory and filename (without extension) is: ${extractDir}`); // Create a variable to store the ext part of the variable" diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 292f83aab..632463ee3 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -1,9 +1,24 @@ const minimum = 1; const maximum = 100; -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +// const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +// console.log(num); + + +// Math.floor() takes the integer Number +// Math.random() will take a number between 1-100; + + // 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 + + + +function getRandomArbitrary(min, max) { + return Math.random() * (max - min) + min; + } + +console.log(getRandomArbitrary(minimum, maximum)); \ No newline at end of file From 80ba22b0d6579f7a49c00b63712cd285460d6c23 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 7 Nov 2024 23:39:49 +0000 Subject: [PATCH 10/25] updateing the line in errors --- Sprint-1/errors/4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index f5c15070f..3de9e854e 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,7 +1,7 @@ // const 12HourClockTime = "20:53"; // const 24hourClockTime = "08:53"; -// this is given an error because we can no start an variable with number So we can fix moving the number +// this is given an error because we can no start an variable starting naming with number, So we can fix moving the number // in the middle or we can write the number instead declare the integer number const hour12ClockTime = "20:53"; From daab52166d30fae70774bda83db896db5ec05b47 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 9 Nov 2024 21:50:59 +0000 Subject: [PATCH 11/25] updating random.js --- Sprint-1/exercises/random.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index 632463ee3..e3bfa4612 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -5,17 +5,20 @@ const maximum = 100; // console.log(num); -// Math.floor() takes the integer Number -// Math.random() will take a number between 1-100; - - - // 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 +/* Math.floor() takes the integer Number + Math.random() will take a number between 0 (inclusive) and 1 (no inclusive) eg. (0.345, 0,123) + Math.random() * (maximum - minimum + 1): this multiply the random decimal number + + + + +// in this example taken from mdn we see the same function being called and will generate a random number between the minimun and maximun function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; From 771f1cb31d25b2572a8db4d91c287674e671b1f0 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 10 Nov 2024 20:06:20 +0000 Subject: [PATCH 12/25] done initials.js --- Sprint-1/exercises/initials.js | 9 +++++++++ Sprint-1/exercises/random.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..66a498593 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -4,3 +4,12 @@ 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 acronym = `${firstName[0]}${middleName[0]}${lastName[0]}` +let initials = firstName[0] + middleName[0] + lastName[0]; + + +console.log(`this option with interpolation ${acronym}`); +console.log(`This string concatenation ${initials}`); diff --git a/Sprint-1/exercises/random.js b/Sprint-1/exercises/random.js index e3bfa4612..38723850c 100644 --- a/Sprint-1/exercises/random.js +++ b/Sprint-1/exercises/random.js @@ -1,27 +1,45 @@ const minimum = 1; const maximum = 100; -// const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -// console.log(num); +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 +// Try logging the value of num and running the program several times to build an idea of +// what the program is doing -/* Math.floor() takes the integer Number - Math.random() will take a number between 0 (inclusive) and 1 (no inclusive) eg. (0.345, 0,123) - Math.random() * (maximum - minimum + 1): this multiply the random decimal number +/* + Math.floor() Math.floor() rounds down the decimal result from the previous step to the + nearest integer. This step ensures the random number is a whole number. + have a random integer between 0 and 99, inclusive. + Math.random() will take a number between 0 (inclusive) and 1 (no inclusive) eg. this + will be decimal numbers (0.345, 0,123) + + Math.random() * (maximum - minimum + 1): is multiplied by 100, creating a new range. + Now, Math.random() * 100 generates a random decimal number between 0 and 100 + (not including 100). Example 0.0, 25.4, 99.99, etc. + (maximum - minimum + 1) This part calculates the range of numbers you want to include, + which is from 1 to 100. Subtracting minimum from maximum gives 99, and adding 1 results + in 100. So, this range means we’re looking to generate a random number between 0 and 99 + and then shift it to between 1 and 100. + + minimum: + Adding minimum (which is 1 in this case) shifts the entire range up by 1. + Now, instead of getting a range of 0–99, the range becomes 1–100. + so, num will now be a random integer between 1 and 100. +*/ -// in this example taken from mdn we see the same function being called and will generate a random number between the minimun and maximun +// in this example taken from mdn we see the same function being called and will generate a +//random number between the minimum and maximum function getRandomArbitrary(min, max) { - return Math.random() * (max - min) + min; + return Math.floor(Math.random() * (max - min) + min); } console.log(getRandomArbitrary(minimum, maximum)); \ No newline at end of file From 78ab25c042d6723f9f7df96ac38586c030681a66 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 11 Nov 2024 00:10:21 +0000 Subject: [PATCH 13/25] done chrome.md --- Sprint-1/explore/chrome.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-1/explore/chrome.md b/Sprint-1/explore/chrome.md index e7dd5feaf..73d6d4236 100644 --- a/Sprint-1/explore/chrome.md +++ b/Sprint-1/explore/chrome.md @@ -10,9 +10,23 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; -What effect does calling the `alert` function have? +---------- alert("hello Maria"); +---------------Hello Maria + +What effect does calling the `alert` function have? show a window with the alert at the top of the browser Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. +--------- prompt("What is your name?"); //maria +--------- var myName = prompt("What is your name?"); +------------- Maria + What effect does calling the `prompt` function have? -What is the return value of `prompt`? + + //prompt will display a dialog text box to interact wit the user, this can be used to ask question and then stored in one variable. this can have two option "ok" and "cancel", if cancel is pressed nothing will run. and this will be "undefine". + + +What is the return value of `prompt`? + + //If the user enters a name and clicks "OK," the input text is stored in the variable myName. + From f100a1b46a3b42c09751d1b2243bfed75141a1fe Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 11 Nov 2024 00:13:49 +0000 Subject: [PATCH 14/25] done updating spaces paths.js --- Sprint-1/exercises/paths.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index cbe9916c4..fa4743bb8 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -9,12 +9,14 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) + /* ================ lastIndexOf() =================== --we use this to obtain the last position of / where is located the File.txt --const base = filePath.slice(lastSlashIndex + 1); with + 1 we start to subtract after / -Index: 0 1 2 ... 37 38 39 40 41 42 -filePath: / U s ... / f i l e .txt -- + + -we use this to obtain the last position of / where is located the File.txt + -const base = filePath.slice(lastSlashIndex + 1); with + 1 we start to subtract after / + Index: 0 1 2 ... 37 38 39 40 41 42 + filePath: / U s ... / f i l e .txt + - */ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; @@ -24,6 +26,7 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(base); // file.txt // console.log(`The base part of ${filePath} is ${base}`); + // Create a variable to store the dir part of the filePath variable const lastDotIndex = filePath.lastIndexOf("."); console.log(lastDotIndex); // index position 49 From 43413136a039f437a0b5a5d6b5c0dd302302d938 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 11 Nov 2024 22:59:09 +0000 Subject: [PATCH 15/25] updating time in the variables with the correct time --- Sprint-1/errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 3de9e854e..7610012b0 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -4,9 +4,9 @@ // this is given an error because we can no start an variable starting naming with number, So we can fix moving the number // in the middle or we can write the number instead declare the integer number -const hour12ClockTime = "20:53"; +const hour12ClockTime = "8:53"; console.log(hour12ClockTime); -const hour24ClockTime = "08:53"; +const hour24ClockTime = "20:53"; console.log(hour24ClockTime); \ No newline at end of file From 7332754a3f2e5bb1eb601a8420ec306c2a1435af Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 11 Nov 2024 23:10:59 +0000 Subject: [PATCH 16/25] done objects.md --- Sprint-1/explore/objects.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Sprint-1/explore/objects.md b/Sprint-1/explore/objects.md index 0216dee56..990ee9ad5 100644 --- a/Sprint-1/explore/objects.md +++ b/Sprint-1/explore/objects.md @@ -3,14 +3,35 @@ In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. Open the Chrome devtools Console, type in `console.log` and then hit enter - + What output do you get? + ---------------- ƒ log() { [native code] } + Now enter just `console` in the Console, what output do you get back? + --------------- console + console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + methods properties built-in Js devtools which can be useful for debugging and tracking the code -Try also entering `typeof console` + +Try also entering `typeof console` + ------------- 'object' Answer the following questions: What does `console` store? + ------------ Is an object Js which contains methos and properties for logging information, displaying errors, warnings, debugging in the browser. + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + ------------ the dot notation between `console.log` or `console.assert` is the access to method(function) store within the console object. + + ---------- eg. With the . operator, we can access the properties in each object within the students array, allowing us to check or modify what’s stored in each object. + +let students = [ + { nombre: "Ana", age: 21 }, + { nombre: "Luis", age: 22 }, + { nombre: "Marta", age: 20 } +]; + +console.table(students); + From c25a3b18a6f30fba881aa2c589d0b734cebfdafb Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 11 Nov 2024 23:53:10 +0000 Subject: [PATCH 17/25] done percetage-change.js --- Sprint-1/interpret/percentage-change.js | 48 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/Sprint-1/interpret/percentage-change.js b/Sprint-1/interpret/percentage-change.js index e24ecb8e1..68a8c95f4 100644 --- a/Sprint-1/interpret/percentage-change.js +++ b/Sprint-1/interpret/percentage-change.js @@ -2,21 +2,55 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; + 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 +/* + 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 + + -------- Number(carPrice.replaceAll(",", "")); this convert string in numbers + -------- replaceAll(",", "") this line is removing the "," and returning just the numbers + -------- console.log(`The percentage change is ${percentageChange}`); this is a function to print what we call inside. + + + + b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? + + ------- In the line 5 we were missing the "," dividing the ("," "") this gave an error. + + + c) Identify all the lines that are variable reassignment statements + + ------- carPrice = Number(carPrice.replaceAll(",", "")); + ------- priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + + + d) Identify all the lines that are variable declarations + + ------- let carPrice = "10,000"; + ------- let priceAfterOneYear = "8,543"; + ------- const priceDifference = carPrice - priceAfterOneYear; + ------- const percentageChange = (priceDifference / carPrice) * 100; + + e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? + ------- The expression Number(carPrice.replaceAll(",", "")) performs two actions: + * carPrice.replaceAll(",", ""): + The replaceAll() method is used on the string carPrice. It removes all commas "," from the + string by replacing them with an empty string "". -// c) Identify all the lines that are variable reassignment statements + * Number(...); + this function is then called on the result of replaceAll(), + converting the string now without commas into a numeric value eg 10,000 => 10000 -// d) Identify all the lines that are variable declarations -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +*/ \ No newline at end of file From 7ed2bbc1461f1f14c9d184e9cf0a67c25315b6bb Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Tue, 12 Nov 2024 15:40:12 +0000 Subject: [PATCH 18/25] update percetage-change.js --- Sprint-1/interpret/percentage-change.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/interpret/percentage-change.js b/Sprint-1/interpret/percentage-change.js index 68a8c95f4..c079a6738 100644 --- a/Sprint-1/interpret/percentage-change.js +++ b/Sprint-1/interpret/percentage-change.js @@ -18,7 +18,7 @@ console.log(`The percentage change is ${percentageChange}`); a) How many function calls are there in this file? Write down all the lines where a function call is made -------- Number(carPrice.replaceAll(",", "")); this convert string in numbers - -------- replaceAll(",", "") this line is removing the "," and returning just the numbers + -------- replaceAll(",", "") this function is removing the "," and returning just the numbers -------- console.log(`The percentage change is ${percentageChange}`); this is a function to print what we call inside. @@ -44,11 +44,11 @@ console.log(`The percentage change is ${percentageChange}`); e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? ------- The expression Number(carPrice.replaceAll(",", "")) performs two actions: - * carPrice.replaceAll(",", ""): + * carPrice.replaceAll(",", ""): The replaceAll() method is used on the string carPrice. It removes all commas "," from the string by replacing them with an empty string "". - * Number(...); + * Number(...); this function is then called on the result of replaceAll(), converting the string now without commas into a numeric value eg 10,000 => 10000 From e4e308fd825fc6d30cfbf4503325bb90207a57b1 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Tue, 12 Nov 2024 21:59:32 +0000 Subject: [PATCH 19/25] done time-format.js --- Sprint-1/interpret/time-format.js | 50 ++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/Sprint-1/interpret/time-format.js b/Sprint-1/interpret/time-format.js index 83232e43a..a003666a7 100644 --- a/Sprint-1/interpret/time-format.js +++ b/Sprint-1/interpret/time-format.js @@ -1,24 +1,58 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 8784; // length of movie in seconds 8784 const remainingSeconds = movieLength % 60; +console.log(remainingSeconds); + const totalMinutes = (movieLength - remainingSeconds) / 60; +console.log(totalMinutes); const remainingMinutes = totalMinutes % 60; +console.log(remainingMinutes); + + const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; console.log(result); -// For the piece of code above, read the code and then answer the following questions +/* + 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? + + -------- 6 in total + -------- movieLength - declared as const + -------- remainingSeconds - declared as const + -------- totalMinutes - declared as const + -------- remainingMinutes - declared as const + -------- totalHours - declared as const + -------- result - declared as const + + + b) How many function calls are there? + + -------- console.log(result); + + c) Using documentation, explain what the expression movieLength % 60 represents + + -------- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder + -------- Remainder: + -------- WITH % we can obtain the remainder between the var movieLength % 60; and stored in remainingMinutes -// a) How many variable declarations are there in this program? + d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// b) How many function calls are there? + -------- This line is taking the leftover remainder in remainingMinutes and leaving just the + total amount that we can divide perfectly in whole number to see how many minutes we have. -// c) Using documentation, explain what the expression movieLength % 60 represents + e) What do you think the variable result represents? Can you think of a better name for this variable? -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? + ------- Result var represent the total runtime of the movie, the nameVar is fine but we can name it as + timeMovie for better readability, as it gives future readers a better idea of the variable's purpose. -// e) What do you think the variable result represents? Can you think of a better name for this variable? + f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + ------- This code works as expected for the most of positive values of movieLength. Just + when I write negative number in the result will show the negative sign. eg. + const movieLength = -4258; + result: -1:-10:-58 +*/ \ No newline at end of file From 6bf5f7f1a9fa0dd3a33cae1b6ac47fa0e46941f6 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Tue, 12 Nov 2024 23:37:46 +0000 Subject: [PATCH 20/25] done to-pounds.js --- Sprint-1/interpret/to-pounds.js | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Sprint-1/interpret/to-pounds.js b/Sprint-1/interpret/to-pounds.js index 60c9ace69..de482f1f6 100644 --- a/Sprint-1/interpret/to-pounds.js +++ b/Sprint-1/interpret/to-pounds.js @@ -6,6 +6,7 @@ const penceStringWithoutTrailingP = penceString.substring( ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 @@ -14,6 +15,7 @@ const pounds = paddedPenceNumberString.substring( const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); + console.log(pence) console.log(`£${pounds}.${pence}`); @@ -23,5 +25,35 @@ console.log(`£${pounds}.${pence}`); // You need to do a step-by-step breakdown of each line in this program // Try and describe the purpose / rationale behind each step -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +/* + To begin, we can start with + 1. const penceString = "399p": initialize a string variable with the value "399p" + + 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); + ----- This is removing the last character from the string and because is negative argument + we should provide the starter point and end index to override the character. + + 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + ----- The padStart function modifies the string by adding a specified character at the + beginning if the string is shorter than the desired length. In this case, + padStart(3, "0") checks if the string has fewer than 3 characters. If it does, + it adds "0" at the beginning until the string reaches a length of 3. eg. + const penceString = "9p"; => £0.09 + const penceString = "44p"; => £0.44 + const penceString = "0p"; => £0.00 + + 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); + ----- Here we are using again subtracting function to extract the integer number removing + the decimals given the argument(0, string.length -2). this means return the string + starting from position 0 and removing the last two characters. + + 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); + ----- Extracting the decimal numbers and gets the last two characters of the string, which + represent the pence part. + + 6. console.log(`£${pounds}.${pence}`); + ----- This line displays the formatted currency value by using template literals to interpolate + the pounds and pence variables into a single string. The £ symbol is added at the beginning + to indicate currency. eg. + const penceString = "399p"; => £3.99 +*/ From 7590fd334a043e97ceccdfaa28ec49a8cc15d130 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Wed, 13 Nov 2024 00:02:09 +0000 Subject: [PATCH 21/25] update PR --- .github/pull_request_template.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ae4e19774..6a3119530 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -17,15 +17,21 @@ If your PR is rejected, check the task list. Self checklist -- [ ] I have committed my files one by one, on purpose, and for a reason -- [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK -- [ ] I have tested my changes -- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/) -- [ ] My changes meet the [requirements](./README.md) of this task +- [x] I have committed my files one by one, on purpose, and for a reason +- [x] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK +- [x] I have tested my changes +- [x] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/) +- [x] My changes meet the [requirements](./README.md) of this task ## Changelist -Briefly explain your PR. +This Pull Request includes JavaScript exercises where I learned about identifying and fixing errors. + +I improved my skills in creating new branches, committing individual files, and committing all changes at once. I also prefer using command-line commands rather than buttons for these tasks. + +I used String.prototype.padStart() for the first time and gained a good understanding of its usefulness. + +To view changes instantly, I used nodemon with a command (while true; do nodemon $(ls *.js | fzf); done) for interactive, real-time feedback. ## Questions From 5ab71ca294463a38174471557668f7c4b4d7cd34 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 2 Jan 2025 01:53:39 +0000 Subject: [PATCH 22/25] update explanation on line 3 about = operator --- Sprint-1/exercises/count.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index fddaf1fe8..770461c97 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -1,10 +1,10 @@ -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 +// 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 updates the value of count by taking its current value, adding 1 to it, +// and then using the assignment operator (=) to store the new value back into count. let count = 0; count = count + 1; console.log(count); -// line 3 is taking the first value and reassigns this new value to count its value + the number 1 - From 3f474482aadd80d1f93dd3af8848b7af596275ab Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 2 Jan 2025 02:06:11 +0000 Subject: [PATCH 23/25] Updated explanation for better undestating on how works the remainingSeconds var --- Sprint-1/interpret/time-format.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sprint-1/interpret/time-format.js b/Sprint-1/interpret/time-format.js index a003666a7..a210ae1fb 100644 --- a/Sprint-1/interpret/time-format.js +++ b/Sprint-1/interpret/time-format.js @@ -31,6 +31,10 @@ console.log(result); b) How many function calls are there? + -------- 4 function calls: + -------- console.log(remainingSeconds); + -------- console.log(totalMinutes); + -------- console.log(remainingMinutes); -------- console.log(result); c) Using documentation, explain what the expression movieLength % 60 represents @@ -41,18 +45,21 @@ console.log(result); d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -------- This line is taking the leftover remainder in remainingMinutes and leaving just the - total amount that we can divide perfectly in whole number to see how many minutes we have. + -------- This line subtracts remainingSeconds from movieLength to remove the leftover seconds. + Then, it converts the difference into minutes by dividing the result by 60. + This gives the total number of whole minutes in movieLength. e) What do you think the variable result represents? Can you think of a better name for this variable? - ------- Result var represent the total runtime of the movie, the nameVar is fine but we can name it as - timeMovie for better readability, as it gives future readers a better idea of the variable's purpose. + ------- Result var represents the total runtime of the movie. While "result" is fine, + a name like "timeMovie" or "formattedTime" would be more descriptive and improve readability. f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer - ------- This code works as expected for the most of positive values of movieLength. Just - when I write negative number in the result will show the negative sign. eg. + ------- This code works as expected for the most of positive values of movieLength. + However, if a negative value is provided for movieLength, the result will show negative values, + which might not make sense in the context of time. For example: const movieLength = -4258; result: -1:-10:-58 + */ \ No newline at end of file From 3ea9f369af2d652239f87768fc5213044102ed10 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Thu, 2 Jan 2025 02:10:01 +0000 Subject: [PATCH 24/25] added another var name option in line 55 --- Sprint-1/interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/interpret/time-format.js b/Sprint-1/interpret/time-format.js index a210ae1fb..a33f6a193 100644 --- a/Sprint-1/interpret/time-format.js +++ b/Sprint-1/interpret/time-format.js @@ -52,7 +52,7 @@ console.log(result); e) What do you think the variable result represents? Can you think of a better name for this variable? ------- Result var represents the total runtime of the movie. While "result" is fine, - a name like "timeMovie" or "formattedTime" would be more descriptive and improve readability. + a name like "movieRunTime", "timeMovie" or "formattedTime" would be more descriptive and improve readability. f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer From dd9ef665835c98fa997616a42de73931aca82607 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sat, 16 Aug 2025 18:25:35 +0200 Subject: [PATCH 25/25] add a console.log to show the typeof variable --- Sprint-1/errors/3.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index 58602de5b..940972a74 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -25,4 +25,5 @@ const cardNumber = 4533787178994213; const last4Digits = cardNumber.toString().slice(-4); -console.log(last4Digits); \ No newline at end of file +console.log(last4Digits); +console.log(typeof(last4Digits)); \ No newline at end of file