-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-Sep | Chandaramani Gaire | Sprint 2 | Sprint 2 Coursework #1575
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
bd936fc
7b9e573
878dae9
982244f
a6a40aa
3fbdf03
9aa6672
63fbd50
453e086
7ab1778
e211f67
62fa645
c32753d
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,9 @@ | ||
| const firstName = "Creola"; | ||
| const middleName = "Katherine"; | ||
| const lastName = "Johnson"; | ||
|
|
||
| // 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 | ||
| const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; | ||
| console.log(initials) | ||
| // // https://www.google.com/search?q=get+first+character+of+string+mdn |
| 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? | ||
| /*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? | ||
| for single line we used // and for multiple line use */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| // 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); | ||
|
|
||
| /* In this case age is not const means variable is not reassigned so that, | ||
| /*we throws a TypeError: Assignment to constant variable*/ | ||
| //I try by let where console.log(age) shows Running] node "c:\Users\Desktop\code your future\Module-Onboarding\Module-JavaScript-Fundamentals\Sprint-2\Sprint-2\2-mandatory-errors\1.js" | ||
| //34. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
|
||
|
|
||
| /*we need to put declare variables(const cityOfBirth = "Bolton";) in first line after using expression console.log. | ||
|
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 reason is right. The variable must exist before Also, write the error name. Run the file now, before you swap the lines. Is it a SyntaxError, a TypeError or a ReferenceError? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
| console.log (last4Digits); | ||
|
|
||
| // 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? | ||
| // 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 | ||
| //Card number is a number not a string so it will throw typeerror. | ||
| // i did not think slice method can not run in number method so that i change it in string | ||
| // when i put capital letter ReferenceError: string is not defined so that nothing last4Digits not showed | ||
| //in the terminal String is the function but string is the normal text. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime12 = "8:53pm"; | ||
| const hourClockTime24 = "20:53"; | ||
|
|
||
|
|
||
| /*variable is not start with number show syntaxerror.*/ | ||
| // i just move the number at the end. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
|
|
||
| const movieLength = 8784; | ||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
|
|
@@ -8,18 +7,28 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; | |
|
|
||
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| 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? | ||
| /* line 1 const movieLength line 3 const remainingSeconds line 4 const totalMinutes | ||
| line 6 const remainingMinutes line 7 const totalHours line 9 const result | ||
|
|
||
| // b) How many function calls are there? | ||
| /* there are one function | ||
| console.log(result); | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| /*The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. | ||
|
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. This is what |
||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| /* This expression convert movies time second into minutes dividend by 60 second. | ||
|
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. Dividing by 60 is the second step. First, |
||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| /* The variable represent the movieLength in second,minutes and hours. | ||
| We can change this name as movieTime. | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| /* In this section we can only use the positive natural numbers but if we put numbers that divide by 60 without a remainder get the exact time like 10, 20 50. | ||
|
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. You are right that positive whole numbers work. Now try Also, 10, 20 and 50 cannot be divided by 60 with no remainder. Which numbers can? |
||
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 13 starts in the middle of a sentence. I think it is about
Math.floor. Please finish it.Two steps are also missing.
Math.random() * (maximum - minimum + 1)isMath.random() * 100. That gives a decimal from 0 up to 100.Math.floorthen makes it a whole number from 0 to 99. So what does+ minimumdo at the end?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.
i write the answer