-
-
Notifications
You must be signed in to change notification settings - Fork 387
London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework #1419
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
9cfc4d2
215069c
dd9a1ca
a102624
8e1e5ad
a0b416f
d26014e
cd349dc
c267bf0
324b237
f5499b3
5eb5f21
18b7731
2cb9c3a
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,2 +1,5 @@ | ||
| 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 can solve this problem by writing those two lines as comments using //, | ||
| // because JavaScript ignores commented lines and they will not be executed by the computer. | ||
|
Comment on lines
+3
to
+5
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 correct, but doesn't quite solve the problem. If we were to run this file as it is, what will happen? Will the code compile? |
||
| 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; | ||
| age = age + 1; | ||
|
|
||
| // There is a constant variable age, which is fixed and it's value cannot be reassigned. | ||
| // If we want to change the value of age, we have to use let instead of const. | ||
|
Comment on lines
+5
to
+6
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 explanation is correct, however If we were to run the code as it is, will the code compile successfully? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
|
||
| // The variable const cityOfBirth = "Bolton"; needs to be declared at first. | ||
| // As it is not declared, JavaScript cannot find out the variable cityofBirth in console.log. | ||
|
Comment on lines
+7
to
+8
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. Another great explanation, however we need to actually fix the problem. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| console.log(cardNumber.toString()); | ||
| const cardNumber1 = cardNumber.toString() | ||
| const last4Digits = cardNumber1.slice(-4); | ||
| console.log(last4Digits); | ||
|
Comment on lines
1
to
+5
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. Really clever solution, I really like it! |
||
|
|
||
| // 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 | ||
| // I think slice () works for strings or arrays not for numbers. That's why the code won't work. | ||
| // Then run the code and see what error it gives. | ||
| // After running code TypeError: cardNumber.slice is not a function this error shows. | ||
| // 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 | ||
| // It gives this error because cardNumber doesn't have slice method. My prediction was beacuse | ||
| // cardNumber is number not string and the difference is that slice method called but it | ||
| // doesn't exist on that type. | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct | ||
| // value | ||
| // Updated the expression in order to get in to the correct value. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const TwelveHourClockTime = "8:53pm"; | ||
| const TwentyfourhourClockTime = "20:53"; | ||
|
Comment on lines
+1
to
+2
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 correct, and it solves the problem. One thing to think about: why did you choose this naming style for these variables? In JavaScript, we usually follow a different naming convention for normal variables than we do for classes, components, or types. Could you please check what naming style is usually used for Have a look at the variable sections: https://curriculum.codeyourfuture.io/guides/reviewing/style-guide/ |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -12,11 +12,27 @@ 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 | ||
| // There are 5 function calls. carPrice = Number(carPrice.replaceAll(",", "")); | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| // In the above 2 lines, 2 replaceAll() functions for carPrice and priceAfterOneyear and after executing them again Number() | ||
| // functions for the 2 variables. | ||
| // At last, console.log() function for printing the executed value. | ||
|
|
||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
| // after running the code, the error is coming from this line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));and | ||
| // the error is SyntaxError: missing ) after argument list. There is a comma missing in replaceAll() syntax. It should be | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // There are 2 variable reassignment statements. | ||
| // const priceDifference = carPrice - priceAfterOneYear; | ||
| // const percentageChange = (priceDifference / carPrice) * 100; | ||
|
Comment on lines
+28
to
+29
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. These lines are declarations, not reassignments. Have another look at what makes a statement a reassignment. |
||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // There are 4 variable declarations lines. | ||
| // let carPrice = "10,000"; | ||
| // let priceAfterOneYear = "8,543"; | ||
|
Comment on lines
+32
to
+34
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. Could you please highlight the lines where the declarations are? |
||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // Firstly this expression replace all the commas from the variable carPrice = "10,000" to "10000" and then it converts | ||
| // string "10,000" to number 10000. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,23 @@ 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 declarations. | ||
|
|
||
| // b) How many function calls are there? | ||
| // There is one function call. | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // The expression movieLength % 60 devides the movieLength by 60 seconds and return the reminder | ||
|
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. A small typo here: |
||
| // which will be stroed in the const remainingSeconds. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // Firstly, Removes the leftover seconds from movieLength and then converts the remaining seconds | ||
| // into whole minutes which will be stored into totalMinutes. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // The variable result reprents the movieLength in hours:minutes:seconds. The variable should be renamed by totalDuration. | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // I have tried with 3 variables, 1515, 9999 & 70052. I observed that this code works succesfully with all the values | ||
|
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. Curious to see if a negative number will work. |
||
| // and gave me results for all the different movieLength in hours:minutes:seconds. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,11 @@ In the Chrome console, | |
| invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
|
||
| What effect does calling the `alert` function have? | ||
| // `alert` function deisplays a popup dialogue box with a message and the user have to click 'ok' button. | ||
|
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. one small typo here: |
||
|
|
||
| Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
|
||
| What effect does calling the `prompt` function have? | ||
| // `prompt` function displays a dialogue box with a message and asks the the user to give input. | ||
| What is the return value of `prompt`? | ||
| //It returns the value which user inputs. In the question it is myName. | ||
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 really like how you have explained this.
Good job!