London | 26-ITP-May | Hugh Mills | Sprint 1 | Sprint 1 Coursework#1450
London | 26-ITP-May | Hugh Mills | Sprint 1 | Sprint 1 Coursework#1450HM-127BTY wants to merge 12 commits into
Conversation
…d console.log to make last4Digits visible.
| 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? No newline at end of file |
There was a problem hiding this comment.
For Reference, to comment multiple lines we can use multi-line comment as below
/*
This is a multi-line comment.
You can comment multiple lines at once.
*/
There was a problem hiding this comment.
Ok ill do that change to all my messages then.
What would the better use of the placement be then?
/*
like this?
*/~
/* or like this? */
There was a problem hiding this comment.
/*
This approach provide better readability.
*/
| // 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 | ||
| // I firsth thought the -4 would not work as it starts on 0 |
There was a problem hiding this comment.
For 0-based index, one can get the length of cardNumber and then take the last 4 digit.
There was a problem hiding this comment.
so for it to work it needs to be:
nst last4Digits = cardNumber.slice(cardNumber.length -4)
So in order to get the last 4 using just -4 wont work, need to add the .length function to cardNumber.
There was a problem hiding this comment.
with .slice() function both the approach works
Approach 1 - to get the last 4 digit, just use cardNumber.slice(-4)
Approach 2 - to get the last 4 digit, just use cardNumber.slice(cardNumber.length - 4)
Gopi-2001
left a comment
There was a problem hiding this comment.
Also try working on Module-Structuring-and-Testing-Data\Sprint-1\4-stretch-explore.
Thank you
| @@ -1,9 +1,12 @@ | |||
| const cardNumber = 4533787178994213; | |||
| const cardNumber = "4533787178994213"; | |||
There was a problem hiding this comment.
This is correct but can you think of a way to convert a number to string using some js functions and use that to get the last 4 digit.
There was a problem hiding this comment.
.toString wold work best I belive:
const cardNumber = 45334533787178994213;
let cardString = cardNumber.toString();
return last4Digits = cardString.length -4
There was a problem hiding this comment.
Here the last line would be like this :
cardString.slice(cardString.length-4)
| // 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 | ||
|
|
||
| // From what I can work out, it is generations a random number between 2 and 100 for the value of num. |
There was a problem hiding this comment.
Math.random() generates random number [0,1) i.e from 0 (including) to 1 (excluding).
Now can you think what will be the value of num, when random number generated is zero.
There was a problem hiding this comment.
from 0 to 1, mostly through decimals
There was a problem hiding this comment.
Think like this
Math.random() generates value in the range [0,1) where 0 is included and 1 is excluded.
Since, maximum - minimum + 1 = 100
Then Math.random()*(100) will provide value in the range [0,100) . Note thatsquare bracket [ or ]means included and normal bracket ( or ) means excluded.
Math.floor(N) - this function provide number greatest integer less than or equal to N
So for this line of code Math.floor(Math.random()*(100)), the number generate will be in the range [0,99] .
Adding minimum makes the range of variable num to [1,100] i.e. increasing the previous range by the value of 1.
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
There was a problem hiding this comment.
what do you think, why it was not working before ?
There was a problem hiding this comment.
Ah the order of them in line of code was wrong, const needs to be before the console.log.
| // 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 | ||
|
|
||
| // Line 3 is taking the value of count, then adding 1 to that value, then making that new value to be the current count. |
There was a problem hiding this comment.
Apart from count = count + 1, can you look for more compact operation to increment variable by 1.
There was a problem hiding this comment.
No the are other approaches, when the requirement is to increase/decrease the value of a number only by 1.
You can go through this - increase-or-decrease-a-number-by-one
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| // a) There are 5 calls made: |
There was a problem hiding this comment.
Yes there are 5 function calls, but you mentioned line 4 and 5 has a total of 4 functions call.
Can you try looking for another one.
There was a problem hiding this comment.
ah yes:
onsole.log(The percentage change is ${percentageChange});
| // a) There are 5 calls made: | ||
| // carPrice = Number(carPrice.replaceAll(",", "")); | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")) | ||
| // b) Error on line 5 for "," it is missing the seperating , between "," and "". |
There was a problem hiding this comment.
Instead of mentioning like that, keep it little for explicit which will easier to pin point the error.
Like - "For function call priceAfterOneYear.replaceAll("," "") comma is missing between the arguments "
Can you look what the term arguments means in Programming language ?
There was a problem hiding this comment.
Thats an object that is only available inside a function.
So for example its "The percentage change is" and ${percentageChange}" would be arguments here :
console.log(The percentage change is ${percentageChange});
| // a) There are 6: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result. | ||
| // b) There is one: console.log. | ||
| // c) It is taking the movieLength and doing a remainder that is showing what is left after the vaule has been divided, in this case wil be 84. | ||
| // I found the info here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder |
There was a problem hiding this comment.
Note Remainder = Dividend % Divisor , and the rule is remainder always strictly less than divisor.
For movieLength % 60, can you re-evalute what the remainder will be ?
There was a problem hiding this comment.
it would be "8784 % 60 = 24"
My math was wrong there. (I think I tried to do it would a calculator)
| // I found the info here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder | ||
| // d) It is removing any extra seconds from the division by 60 so that is is showing as whole numbers without decimals. | ||
| // e) Result is showing the movies duration but broken down to hours:minutes:seconds, I think it should be movieDuration to help describe it better. | ||
| // f) Yes, it does work to show the lenght even if it is only in one section, though it does show values of 0, could clean it up to show nothing. No newline at end of file |
There was a problem hiding this comment.
movieLength is a Number and apart from 0 what all different number do you think will provide incorrect response. Think of different Types of Number we have in Number system.
There was a problem hiding this comment.
Negative numbers or decimal numbers?
Learners, PR Template
Self checklist
Changelist
Completed the tasks for Complete Sprint 1 Coursework:
1-key-exercises
2-mandatory-errors
3-mandatory-interpret