diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..8223aae79 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ 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 + + +//Answer: it's adding one to the value of Variable count which is 0, in line 3 the value of count changes to 1 \ 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..59ea2e57b 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,13 @@ 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 +console.log(initials); \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..2d9d17650 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -14,10 +14,18 @@ const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); + + +const dir = filePath.slice(0,lastSlashIndex); +const ext =filePath.slice(filePath.lastIndexOf(".")+1); + +console.log(ext); +console.log(dir); + // 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 = ; +// const ext = ; // 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..e1ab815c6 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,14 @@ 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 + + + +//Answer (before running the code): +// I believe a random number will be multiplied by 100 and added by 1 so will have 101, 201, 301, 401, 501..... +//maximum which is 100 minus minimum which is 1 and added to 1 will result to 100, 100-1+1=100, and it will be multiplied to 100 and added to minimum which is 1. + +console.log(num); + +//Answer (After running the code): +//Math.random unlike my expectations doesn't produce an integer, it produced a random Floating number between 0 and 1, so we get answer in range of 1 - 100 diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..2cf94cbf2 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-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 +// 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? + + +//we should comment them out, in VS Code the shourtcut is cntrl + c, cntrl + k. the symple of commenting out for each coding language differs and computers don't execute the lines that are commented out \ 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..34201c80d 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,8 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +console.log(age); + +//In this case we cann't use const variable if we want to change its value later on, so it should be let \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..d8bf14f07 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,7 @@ // 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}`); + +//The error was Referrence Error which is cause by using a variable before declaring it. JavaScript reads from top to bottom, so we have to declare the variable first and the use it. I moved the cityOfBirth variable one line above the console.log funciton \ 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..3388492b0 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,7 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const lastFourDigits = String(cardNumber).slice(-4); + +console.log(lastFourDigits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +9,7 @@ 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 + + +//Prediction and explaination: +//index value is only for string and array data types, in this case it throws an error since cardNumber holds a number not string or arrray. \ 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..abe7ea6e9 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 twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; + +//Answer: we can declare or name our variables using numeric values, but we can't start with a number, so we can't name our variables as 20:53 or 08:53 +// Furthermore, the variable's name doesn't match the content of the variables and the naming should be opposite, to match the content of the values. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..8c8e53ff0 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,18 @@ 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 +// 3 function calls: Numbers(), variable.replaceAll(), and console.log // 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? +//On Output and Problems Console tabs, it said on line 5, a comma was missing, after comparing with the upper line that has the same function, I added a comma to separate the arguments that were passed to the function. + // c) Identify all the lines that are variable reassignment statements +// Line 4 and 5, because we are assigning a new value to the variables that are already declared in the previous line (1 and 2) // d) Identify all the lines that are variable declarations +// line 1,2,7,8 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//Number convert the current values ,in both variables declared in line 1 and 2, to number after removing comma from the values diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..eb01dc618 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,23 @@ 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? +// Answer: 6 variables: line 1,3,4,6,7,9, wherever there is const or let word // b) How many function calls are there? +// Answer: only 1: Console.log // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +//Answer: the expression will divide movieLength which is second to 60 and extract the REMAINDER of the operation. The remainder in this case can have a range of values between 0-59s + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//Answer: in line four we are subtracting the remainder of movieLength divided by 60 to make a divisible number by 60, because we want to know how many minutes the movieLength is in minute not second unit and minutes should be integer not float. + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// Answer: the length of the movie in the following format: hr:min:sec, movieLength would be an appropriate alternative for this variable, however since we already have a variable with the same name and const type which the value cannot be changed, "remainingDisplayTime" is the best name that reaches my mind. + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//Answer: Yes I believe it would work for all the values, since we divide the movieLength by 60 one time to get the minutes and two time to get the hours, if we have a 0 second movie the calculation would still run without throwing an error since 0 is not in the denominator and is numerator. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..acb328616 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,8 @@ 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): extract every characters in penceString variable except the last one (penceString,length -1) +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the number is at least 3 digit long and if not adds 0 before the number not to change the value. +// 4.const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2): extract everything but the last 2 digits (-2) from paddedPenceNumberString variable to get the pound number +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): similar to pound, it extract the last two digits of paddedPenceNumberString to get the pence number, If there’s only one digit, it ensures two digits by adding a trailing zero +// 6. console.log(`£${pounds}.${pence}`): in this line the pound value will be displayed to the user in this format: £ pound. pence diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..894d89572 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,15 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +A pop-up box will appear with the text of Hello world! 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`. What effect does calling the `prompt` function have? +A pop-up box will appear with the text what is your name? and input text box to let the user type their names +If they press cancel, whether or not they have entered their name in the text box- in the console we will see the 'null' in the next line of the prompt +If they enter their name, and press ok, in the console they can view their name. + What is the return value of `prompt`? +The input of the what is your name pop-up text +If they enter their name, and press ok, in the console they can view their 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..777ff03bb 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,17 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +undefined if () were typed +ƒ log() { [native code] } if () were not typed Now enter just `console` in the Console, what output do you get back? +console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` +object Answer the following questions: -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +What does `console` store? some functions that can be called like "log" +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +we are calling assert or log function from console which stores these functions. The "." tells the program to access the console object and call the function log, or assert within console object. diff --git a/prep/Convert.js b/prep/Convert.js new file mode 100644 index 000000000..0bb9df43d Binary files /dev/null and b/prep/Convert.js differ diff --git a/prep/example.js b/prep/example.js new file mode 100644 index 000000000..9401bf0c3 --- /dev/null +++ b/prep/example.js @@ -0,0 +1,2 @@ +console.log("Hello, this is my JavaScript file!"); +console.log("Node.js is executing this file."); \ No newline at end of file