diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..17b7e70c7 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/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 variable count to a new value.Taking it current value adding 1 to it and storing the result back into count. \ 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 47561f617..202c67880 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.charAt(0) + middleName.charAt(0) + lastName.charAt(0); // 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 ab90ebb28..3e2b4d020 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,12 @@ 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 lastDotIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDotIndex); + + + // 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 292f83aab..d826fb62b 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,21 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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.random() returns a random number/ decimal number between 0 (inclusive), and 1 (exclusive). + +//Math.random() always returns a number lower than 1. + +// * (maximum - minimum + 1) multiplying by this is to give a range of possible values. + +// adding the minimum at the end is to give a range value between the minimum and maximum inclusive. + +// Math.floor usually rounds the number down to the nearest integer. + +console.log (num); // first print is 24 +console.log (num); // second print 3 +console.log (num); // third print is 17 +console.log (num); // fourth print is 70 +console.log (num); // fifth print is 7 \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..961ab39b3 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,9 @@ -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. + +//SyntaxError: Unexpected identifier 'is' that was the error after i ran node. +// I think javascript is trying run them word for word and found is in an unfamiliar place. +// could also be that its trying to run is as a code which is not correct. + +/* To make this correct we can add a double line(//) before the statement to make it a single line comment, +or we can add a line and asterisk before and after to make it a double line comment */ \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..b27472891 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,17 @@ const age = 33; age = age + 1; + +//TypeError: Assignment to constant variable. +// here we already have a variable constant age=33, now we are trying to reassign the variable constant. + +// to enable this work, we can say; +let age = 33; +age = age + 1; + +console.log(age); //34 +//this will be a way to fix error. + + + + diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..e71c7547f 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,7 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + + +//ReferenceError: Cannot access 'cityOfBirth' before initialization +// you always need to declare a variable before using it. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..71ab5e8d0 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,8 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); + + +console.log(last4Digits); // "4213" // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +10,9 @@ 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 + + +/* I don't think it will work, because card number is a number, +and .slice() is a string method and we must convert the number to string method to work*/ + +//TypeError: cardNumber.slice is not a function. this was after running node. \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..1e85ac63f 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,11 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const Hour12ClockTime = "20:53"; +const hour24ClockTime = "08:53"; + +console.log(Hour12ClockTime); //"20;53" +console.log(hour24ClockTime); // "08:53" + +// SyntaxError: Invalid or unexpected token. +// variable names cannot start with number. + +// renaming our variable would be the right thing. + diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..2c44b2b6a 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -20,3 +20,14 @@ console.log(`The percentage change is ${percentageChange}`); // 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? + + +// a) 5 function calls. 2 in line 4, 2 in line 5, and 1 in line 10. + +// b) SyntaxError: missing ) after argument list. There is a missing comma after argument. It can be fixed by adding a comma. + +// c) line 4 and 5. + +// d) line 1,2, 7, and 8. + +// e) The expression is used to remove commas from the string and convert it into a number so it can be used in calculations. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..777adeb3b 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = -8784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -23,3 +23,20 @@ console.log(result); // 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 + + + +// a) 6 variables declarations. + +// b) 1 function call. + +/* c) The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. +In this case it will give the remainder of 8748 % 60 */ + +// d) It simply wants to get the length of the movie in minutes. subtract the remaining seconds from the movie length and convert to minutes. + +// e) It represents the movie durations in hours, minutes and seconds. (movie duration). + +/*f) I have tried three values and it worked. It will work perfectly for larger and smaller numbers. +However, with negative values it gives negative figures.*/ + diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..3327d27cf 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,13 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// 2.line 3-6 function is trying to remove the p and make the strings numeric only. + +// 3.line 8 ensure there are three characters and can split equally to pounds and pence. + +// 4.line 9-12 this is extracting pounds from the number. + +// 5.line 14-16 ensure the pence always have 2 digits. + +// line 18 gives the value in pounds and pence. diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..98fd95b45 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -16,3 +16,9 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? What is the return value of `prompt`? + + +line 13- when i ran the function on console tab, it showed a new word hello world in the next line. + +line 17&18 - when i ran the 'prompt' function it pop up a box for imputing my name and it returned undefined. +after i wrote myname in the next line it brought out my name. \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..e38d3de84 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -14,3 +14,17 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +line 7 =ƒ log() { [native code] } + +line 9 = console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + +line 11 = 'object' + + +line 15 =console is like an object that helps to store methods used for debugging and printing output in the browser’s developer tools. + + + line 16 = 'console.log'means access or get the log function fom the object console. + 'console.assert' means access or get the assert function from the object console. + while the '.' is an access operator that access methods or properties from and object.