Repository navigation
London | 26-ITP-Sep | Rawan Almutairi | Sprint 2 | JavaScript exercises #1628
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
base: main
Are you sure you want to change the base?
Changes from all commits
f6c55f9
9082c8c
94e8a72
1cf24f7
c253857
0f68f8b
adcbbf9
b12c3a3
8e67204
029ba69
d35032e
24f5004
7da57e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job! This is a very clean and clever solution using template literals and bracket notation. Quick question: Is there another built-in string method besides bracket notation you could use to get the first character?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string.prototype.replace() |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spot-on implementation for extracting Quick question: When using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we omit the first index, the string won't break but will go to the wrong location; in the case of omitting the 0 index, it will delete anything before the last index ''/' |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear breakdown of the math logic! Just remember the order: Quick question: What purpose does the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to search for this one to understand it. Math.random() generates a decimal that ranges between the values 0 and 0.99999, so when we try to scale it up Math.random() will generate values between 0 and 8.9999, so it doesn't include 9. This becomes an issue when we use Math.floor as it will round it to the nearest whole number, and because it doesn't include the number 9, it will round down from 0 to 8. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| 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 don't want the computer to run these 2 lines - how can we solve this problem? | ||
| //we use a (//)) to comment it. So the computer doesn't execute the text. |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spot-on distinction between Quick question: Is there a shorthand assignment operator you could use instead of writing
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, += |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
| //a shorthand assignment operator | ||
| //yes, += | ||
| //an error message shows up: TypeError: Assignment to constant variable. | ||
|
|
||
| //to solve this, we replace const with let to make the variable value changeable, then we run the program |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accurate explanation! Trying to use Quick question: Do you know the technical term for the area in the code before a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| //The variable was declared after the print function, so the program doesn't know what is cityofBirth. Therefore, it can't perform the print function or execute before declaring the variable | ||
|
|
||
| //to solve this, we reverse the order of both lines so the declaration comes before the print functions | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite a ReferenceError here— Quick question: What method can you call on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toString() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); | ||
| //the output is 4213 | ||
| // 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 | ||
| //it won't work because cardNumber is not a string | ||
| // Then run the code and see what error it gives. | ||
| //TypeError: cardNumber.slice is not a function so a string method can't br used with it | ||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // The error is caused because card number is a number not a string and toString is a string method so its a different type of data | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spot-on explanation! Variable names cannot start with numbers. Quick question: While starting with a capital letter works syntactically, what is the standard JavaScript naming convention (case style) usually used for variables made of multiple words like this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| const twintyFourhourClockTime = "20:53"; | ||
|
|
||
| //we see the error message SyntaxError: Invalid or unexpected token, | ||
|
|
||
| //because variable conventions don't allow numbers to be the start of variable names | ||
|
|
||
| //to solve this issue, we change the numbers to words format | ||
|
|
||
| //done | ||
|
|
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spot-on answers! Your breakdown of line 5's syntax error, reassignments, and the purpose of Quick question: Why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spot-on analysis! Your observation about leading zeros triggering an octal syntax error is a brilliant and advanced catch. Quick question: If
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the digit zero is before the 5. We create a numerical string, then convert the string to a numerical value or add the zero digit as a string before the number or we modify the function to include strings so we can manipulate the numbers. |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great step-by-step breakdown! You clearly traced how Quick question: Why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It specify the starting values so we don't have random numbers that could cause a bug in the program. We restrict it. |
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.
Great job! You correctly identified how the variable is initialized and reassigned.
Quick question: How would you specifically describe the role of the
=sign in that second line?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.
//Line two we see the variable count using the = sign to assign a new value whcih is count previous value + 1
//the equal sign in line two is assigned operator that stores the new value to the variable