-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-Sep | Shirin Panahian | Sprint 2 | Complete Sprint 2 Coursework #1545
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 16 commits
8e8fb39
21470a9
a9e44ee
59481d1
fda7c0d
a6dbd79
5bc72b3
516c24c
01adbcc
a52cfdb
71baeb7
4e607b2
837636d
373e8ae
cfee6b6
ccb29be
73b8e26
7d41310
e765236
8c04eec
9663fde
7fa22d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,6 @@ | ||
| const firstName = "Creola"; | ||
| const middleName = "Katherine"; | ||
| const lastName = "Johnson"; | ||
| const initials = `${firstName.charAt(0)}` + `${middleName.charAt(0)}` + `${lastName.charAt(0)}`; | ||
| console.log(`${initials}`); | ||
|
|
||
| // 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. | ||
|
|
||
| const initials = ``; | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,12 @@ const minimum = 1; | |
| 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 | ||
| // 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 | ||
| //num represents a random whole number between 1 and 100, | ||
| //first we calculate value inside parentheses(maximum - minimum +1) = 100 -1 + 1 =100 | ||
| // math.random return number between 0 and 1 | ||
| // math.random() * 100 give us a integer number | ||
|
Contributor
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. Have a look at this line again. Try running
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. Yeah I write wrong, Math.random() * 100 does not give us an integer. It gives us a decimal number between 0 and 100 for example 0.83488 *100 = 83.488. This is why we use Math.floor() . Math.floor(83.488) rounds the number down to 83. Then we add 1, giving us 84.
Contributor
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, exactly that. |
||
| // math.floor round down the number | ||
| // add 1 to the result | ||
| //for example math.floor((0.783 *100))=78 + 1 = 79 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| 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? | ||
| //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? | ||
|
|
||
| /*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 can put "//" in the beginning of the line so computer ignore them | ||
| // or put them between /* and */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // 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}`); | ||
| //We should use let if we want to change the value. | ||
|
Contributor
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. Your fix is right. In
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. Before I changed const to let node show this error message: (Assignment to constant variable.)
Contributor
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. That's the one. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // 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}`); | ||
| // This error (Cannot access 'cityOfBirth' before initialization) is because we need to declare the variable before using it. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,4 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| // 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 | ||
| // 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 | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
| console.log(`${last4Digits}`); | ||
| // we get error (cardNumber.slice is not a function) because slice is a String method |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime12 = "8:53pm"; | ||
| const hourClockTime24 = "20:53"; | ||
| //JavaScript variable names cannot start with a number. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = 5467; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -12,14 +12,25 @@ 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? | ||
| /* there are 6 variable declaration in this program. | ||
| 1- movieLength , 2- remainingSeconds , 3- totalMinutes | ||
| 4- remainingMinutes , 5- totalHours , 6- result */ | ||
|
|
||
| // b) How many function calls are there? | ||
| /* one function | ||
| Line 10 : 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 | ||
| // Remainder(%) : Return the remainder left over when one operand is divided by a second operand | ||
| // console.log(13 % 5 ); 3 | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // This expression converts movie length from seconds into minutes | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // Variable result represent the movie length formatted as hours, minutes, seconds , | ||
| // another name could be movieTime | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // This code works for normal positive number representing but for negative number and very big number it is not working | ||
|
Contributor
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. Negative numbers are right. A very big number is fine though, try
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. The code work for big number, I try 999999 and it return correct number. However, if movieLength = 90.5, it prints 0:1:30.5. This is not a good way to show a time because the seconds contain decimals. So the code works properly for whole numbers, but not for negative numbers and decimal numbers because the result can contain decimal values.
Contributor
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. Good. 59 is worth a try too: it prints 0:0:59, which is the other thing that looks wrong. |
||
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.
Run this file and read the dir line carefully. It prints
.../week-1/interpre, and the folder is calledinterpret. One character is being lost. What is the- 1doing at the end of this line, and doessliceneed 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.
The - 1 makes the slice stop one character too early, which removes the t from interpret. It isn’t needed. thank you for mention .
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 it, the dir line prints the full folder name now.