-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NW6 |Zeliha Pala | JS1 Module | [TECH ED] Complete week 1 exercises | Week1 #133
base: main
Are you sure you want to change the base?
Conversation
//const age = 33; | ||
//age = age + 1; | ||
|
||
//we can not reassign a new value to a constant. if we reassign a value to a const variable, we will get a "TypeError." but we can do this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's right 👍
const cityOfBirth = "Bolton"; | ||
console.log(`I was born in ${cityOfBirth}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect 👍
console.log("Last 4 digits : ${last4Digits}"); | ||
|
||
/*1.The slice method is typically used with strings to extract a portion of the string. | ||
to extract the last 4 digits of the card number, we must first convert it to a string and then use the slice method.So we put the number in string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your analysis of the problem is correct. However, the tasks asks to "try updating the expression last4Digits is assigned to, in order to get the correct value"
How might you update the expression to make the value that's being sliced into a string?
week-1/errors/4.js
Outdated
const 24hourClockTime = "08:53"; | ||
//variable names in JavaScript cannot start with a digit. They must start with a letter, underscore (_), or dollar sign ($). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've identified the problem correctly. Don't forget to fix the statements to fix the error
week-1/exercises/count.js
Outdated
|
||
// 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 | ||
|
||
// The assignment sign is used to assign a new value to a variable. Here the count variable will have a new value of 1, which means it has been incremented by 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. It's a reassignment statement
@@ -8,3 +7,11 @@ const num = 56.5467; | |||
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) | |||
|
|||
// Log your variables to the console to check your answers | |||
|
|||
const wholeNumberPart = Math.floor(num); // Extract the whole number part 56 | |||
const decimalPart = num - wholeNumberPart; // Calculate the decimal part; num is 56.5467 - wholeNum is 56 so 0,5467 is decimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your thinking here is correct. However, there are some nuances with using floating point numbers, that you will see when this code is run.
To get the right answer, try looking up how to maintain number of decimal places when subtracting floating point numbers in javascript
week-1/exercises/initials.js
Outdated
let initials = | ||
firstName.charAt(0).toUpperCase() + | ||
middleName.charAt(0).toUpperCase() + | ||
lastName.charAt(0).toUpperCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct & gets the right answer. Good use of 'toUpperCase' for completeness, but is it perhaps redundant in this situation?
week-1/exercises/paths.js
Outdated
|
||
// 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(filePath.indexOf("/"), filePath.lastIndexOf("/")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've got to the correct answer here. Could you reuse the "lastSlashIndex" variable declared above?
console.log(dir); | ||
|
||
// Create a variable to store the ext part of the variable .txt file.txt | ||
const ext = filePath.slice(filePath.lastIndexOf(".")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
@@ -3,6 +3,8 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, try to explain what the expression on line 4 is doing. Run the program a few times - do you get the same value or different values? Also, try breaking down each part of the expression to help understand
week-1/explore/objects.md
Outdated
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 the syntax `console.log` or `console.assert` mean? | ||
In JavaScript, the console is like a toolbox for developers. It helps them see messages, warnings, and errors while building and fixing things on a website. It's a way to peek behind the scenes and understand what's happening in their code. console.log is like a sticky note to jot down messages for themselves, and console.assert is a tool to shout out if something isn't right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well explained!
|
||
In particular, what does the `.` mean? | ||
|
||
The . (dot) in JavaScript is called the dot notation and is used to access properties and methods of objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, in the case of console.log and console.assert, what is being accessed?
@@ -12,9 +12,15 @@ 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 | |||
//Number is a function. replaceAll is a method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one. So how many function calls would you say are in this file?
|
||
// c) Identify all the lines that are variable declarations | ||
//let keyword is used to declare two variables, carPrice and priceAfterOneYear, and initialize them with string values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other keywords used in this code that could also declare variables?
|
||
// b) Identify all the lines that are variable reassignment statements | ||
//carPrice = Number(carPrice.replaceAll(",", "")); // converts to number takes the string quato | ||
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
//the values of the variables carPrice and priceAfterOneYear has bee changed with removing commas and converting them to numbers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good explaination 👍
const remainingMinutes = totalMinutes % 60; | ||
const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
const remainingHours = totalHours % 24; | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nearly! It looks like you're missing 1 here 👀
|
||
// b) How many function calls are there? | ||
// b) How many function calls are there? 1 | ||
//console.log(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent spot! ⭐
|
||
// c) Using documentation on MDN, explain what the expression movieLength % 60 represents | ||
//This is modulo operation, and it returns the remainder of the division. Here it says the variable movieLength, is divided by 60 and The % modulo operator, returns the remainder of the division operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👌
/* It expresses the length of the movie in terms of hours, minutes, and seconds. | ||
The format is HH:MM:SS, where HH is the remaining hours, MM is the remaining minutes, and SS is the remaining seconds. | ||
My suggestion for result variable is : | ||
const movieDurationDisplay */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍
// Decide the result should be for those values, then test it out. | ||
|
||
// Can you find any values of movieLength which don't give you what you'd expect? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've got the right answer above. Given that, what are some example values for movieLength that might cause problems for the code?
week-1/interpret/to-pounds.js
Outdated
); | ||
|
||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // padStarts add a zero infront of the number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
padStart will only add 0 in front in certain situations. What situations are that? In this case, how many 0s are added in front of the number?
week-1/interpret/to-pounds.js
Outdated
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
paddedPenceNumberString.length - 2 // last two numbers ignored we have 03 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right yet. What adds the 0?
week-1/interpret/to-pounds.js
Outdated
); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
//This method is used to pad a string with a specified character at the beginning until it reaches a certain length. While doing this, the original string remains unchanged; a new string is returned.The first parameter of the padStart method specifies the target length, and the second parameter specifies the character to be added during the padding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, you've explained the padStart method. That's not used in this statement. Try to break this statement down to it components and explain what it's trying to do
Overall really great work here, Zeliha. You're clearly understanding some fundamental concepts in Javascript and are able to apply them to the exercises. I've left a few comments to work on. I'm also curious to know if you attempted the chrome exploration task(week-1/explore/chrome.md)? Well done! |
Thank you for the code review @varuna-v I tried to fix the codes by researching a bit more based on your suggestions. It really helped me to understand better. Thanks again. |
|
||
//The padStart method is used to pad the start of a string with a specified character (or a specified string) until the resulting string reaches a given length. Here, we are using padStart to ensure that paddedPenceNumberString is at least 3 characters long. If the length of penceStringWithoutTrailingP is less than 3 characters, it will pad the start of the string with zeros until it reaches a length of 3.This method is used to pad a string with a specified character at the beginning until it reaches a certain length. While doing this, the original string remains unchanged; a new string is returned.The first parameter of the padStart method specifies the target length, and the second parameter specifies the character to be added during the padding. | ||
|
||
// Since the length of penceStringWithoutTrailingP is already 3, padStart does not add any zeros, and paddedPenceNumberString remains "399".So, in this case, no zeros are added in front of the number because the length requirement is already met. If the length was less than 3, it would pad with zeros accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your explanation looks like you have understood it really well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good explanations of the code. And very clearly written. 👍
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.