diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..4e1456937 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,7 @@ 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 + +console.log(`value of count is ${count}`) + +// what line 3 doing is add 1 to current value of "count" and saving or assigning the new value (which is 1) as new value diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..972c09647 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -9,3 +9,9 @@ let initials = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn +function getInitial(firstName, middleName, lastName) { + return firstName[0] + middleName[0] + lastName[0]; +} + +initials = getInitial("Creola", "Katherine", "Johnson"); +console.log(`initials is ${initials}`); diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..e713897e6 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,11 @@ 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(1, lastSlashIndex); +console.log(dir); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +const dotIndex = base.lastIndexOf("."); +const ext = base.slice(dotIndex + 1); +console.log(ext); + +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..e099d1731 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -5,5 +5,11 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 + +//Math.random() -> generates zero base random number +// we need to multiply with digit number needed to allow possible number generated +//Math.floor() method will round up to the base integer generated + // 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 +console.log(num); diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..e6b744a05 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/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-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..41e7f21a4 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 +//create variable age const age = 33; + +//reassign variable age by 1 (+1) age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..d64dd7525 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,8 @@ // 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}`); + +//it's not working because variable cityOfBirth was not defined. +//change the position of -- const cityOfBirth = "Bolton"; -- before the logging will fix the problem diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..ad181e425 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,13 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const cardNumberStr = cardNumber.toString(); +const last4Digits = cardNumberStr.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 // Then run the code and see what error it gives. +console.log(last4Digits); // Consider: Why does it give this error? Is this what I predicted? If not, what's different? +//can not slice a number, the given card number is integer NOT a List or array // Then try updating the expression last4Digits is assigned to, in order to get the correct value +//fix by give double quotes to turn the number to sting or make a new variable assign cardNumber.toString() diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..95482db73 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const ClockTime_12Hour = "20:53"; +const ClockTime_24hour = "08:53"; + +//variable name convention issues... +//variable name should not started a number diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..1099d0ad4 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ 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; @@ -12,11 +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 - +//------->ans: build-in function call line numbers 4,5 and 10 // 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? - +//------->ans: error at line 5. +//------->ans: add a missing comma // c) Identify all the lines that are variable reassignment statements - +//------->ans: line 4 (carPrice) and line 5 (priceAfterOneYear) // d) Identify all the lines that are variable declarations - +//------->and: line 1 and 2 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//------->and: replace character comma with nothing or in other words remove it or delete it diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..7826fcca8 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 = 86401; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,15 @@ 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? - +//------->ans: 6 // b) How many function calls are there? - +//------->ans: 1 at the last line, that is console.log() .. it is a built-in function. // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - +//------->ans: 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. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +//------->ans: (movieLength - remainingSeconds) / 60; // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//------->ans: it generates a number in "seconds", for selection of name? the selected one is fine. as long as it follows the variable names convention and the reader or debugger easily understand it. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//------->ans: it has a constrain or maybe limitation, that is if value movie length is bigger that 86400 the time shown not appropriate, it should give a hint that it more than a day diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..29b72fd4e 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,19 +1,24 @@ -const penceString = "399p"; +const penceString = "9p"; //init variable const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 -); +); //remove p character at the end of the variable +console.log(penceStringWithoutTrailingP); + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // +console.log(paddedPenceNumberString); //give format of 3 zeroes if the number is less than 3 digits. -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 -); +); //get ponds value conversion changes for given pence + +console.log(pounds); const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + .padEnd(2, "0"); //get the reminds after conversion to pounds console.log(`£${pounds}.${pence}`); diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..6356d05d2 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -1,6 +1,6 @@ Open a new window in Chrome, -then locate the **Console** tab. +then locate the **Console** tab. (short cut for linux ctrl+shift+j) Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. @@ -9,10 +9,16 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; +ans: done! What effect does calling the `alert` function have? +ans: pops out a message with given strings inside alert arguments 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`. +ans: myname = prompt("What is your name?"); What effect does calling the `prompt` function have? +ans: pops out a message with input field and we can store the input value into a variable + What is the return value of `prompt`? +ans: return value is the string given by user diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..52c71625b 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -3,14 +3,17 @@ 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 +ans: done! What output do you get? - +ans: undefined Now enter just `console` in the Console, what output do you get back? - +ans: a list of available methods for console. Try also entering `typeof console` - +ans: done! Answer the following questions: - +ans: object What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +ans: console.log() will print given parameter in it, +console.assert(, ) only print out the given comment if expression inside it is fault or false diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..84cc80243 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -6,7 +6,7 @@ // =============> write your prediction of the error here function square(3) { - return num * num; + return num * num; } // =============> write the error message here @@ -15,6 +15,4 @@ function square(3) { // Finally, correct the code to fix the problem -// =============> write your new code here - - +// =============> write your new code here \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..ef2072b50 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,5 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + // return the BMI of someone based off their weight and height +}