Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

zelihapala
Copy link

@zelihapala zelihapala commented Nov 11, 2023

Learners, PR Template

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
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

//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;

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}`);

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 */

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?

const 24hourClockTime = "08:53";
//variable names in JavaScript cannot start with a digit. They must start with a letter, underscore (_), or dollar sign ($).

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


// 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.

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

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

let initials =
firstName.charAt(0).toUpperCase() +
middleName.charAt(0).toUpperCase() +
lastName.charAt(0).toUpperCase();

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?


// 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("/"));

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("."));

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

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

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.

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.

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

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.

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

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;
*/

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);

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.

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 */

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?

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?

);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // padStarts add a zero infront of the number

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?

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
paddedPenceNumberString.length - 2 // last two numbers ignored we have 03

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?

);

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.

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

@varuna-v
Copy link

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!

@zelihapala
Copy link
Author

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.

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.

Copy link

@HadikaMalik HadikaMalik left a 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. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants