-
-
Notifications
You must be signed in to change notification settings - Fork 218
London | 25-ITP-Sep | Adnaan Abo | Sprint 1 | Coursework/sprint 1 #711
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 10 commits
bae8316
96e3fdb
e0e0e10
0a27532
afc7816
17adfbd
23e660e
88837ec
784ff5d
ee4627a
fbf9e94
405be77
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,6 +1,14 @@ | ||
let count = 0; | ||
|
||
count = count + 1; | ||
count = count + 3; | ||
|
||
// 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 updating the value of the count variable by adding 1 to its current value. The = operator | ||
// is used to assign the new value (count + 1) back to the count variable. | ||
// we can also say that the = operator is taking the value on the right side (count + 1) and storing it | ||
// in the variable on the left side (count). | ||
|
||
// We can see the result of our code by logging the count variable to the console | ||
console.log(count); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
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 use // to comment out a single line | ||
// or we can use /* to start a multi-line comment | ||
// and end it with */ | ||
|
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; | ||
|
||
// to reassign the value of age by 1 we need to use let instead of const | ||
|
||
console.log(age); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
// what's the error ? | ||
// we need to declare the variable before we use it in the console.log statement | ||
|
||
|
||
console.log(`I was born in ${cityOfBirth}`); | ||
const cityOfBirth = "Bolton"; | ||
console.log(`I was born in ${cityOfBirth}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
//const last4Digits = cardNumber.slice(-4); | ||
|
||
// The last4Digits variable should store the last 4 digits of cardNumber | ||
|
||
// However, the code isn't working | ||
// the error is that slice is not a function for numbers, it is a function for strings and arrays | ||
|
||
// Before running the code, make and explain a prediction about why the code won't work | ||
// My prediction is that the code will give an error because slice is not a function for numbers | ||
|
||
// Then run the code and see what error it gives. | ||
// typeError: cardNumber.slice is not a function | ||
|
||
// Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
// It gives this error because slice is not a function for numbers, it is a function for strings and arrays. This is what I predicted. | ||
|
||
// Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
const cardNumberString = cardNumber.toString(); | ||
const last4DigitsCorrected = cardNumberString.slice(-4); | ||
console.log(last4DigitsCorrected); // Should print 4213 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
const a24HourClockTime = "20:53"; | ||
const a12hourClockTime = "08:53"; | ||
|
||
// The 12HourClockTime variable should store the time in 12-hour format | ||
// The 24hourClockTime variable should store the time in 24-hour format | ||
|
||
// However, the code isn't working | ||
// the error is that the variable names are not valid because they start with a number | ||
// Variable names cannot start with a number | ||
|
||
console.log(a24HourClockTime); // Should print: 08:53 | ||
console.log(a12hourClockTime); // Should print: 20:53 |
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,17 @@ 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 in this file, they are on lines 1, 2, 5, 6 and 9 | ||
|
||
// 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? | ||
// the error was coming from line 5 there was a comma missing between the 2 quotations ("," "") by adding the comma the code was fixed and it worked as it should. | ||
|
||
// c) Identify all the lines that are variable reassignment statements | ||
// the variable reassignment statements are on lines 5 and 6 | ||
|
||
|
||
// d) Identify all the lines that are variable declarations | ||
// the variable declaration statements are on lines 1, 2, 4, 7 and 8 | ||
|
||
|
||
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
/* the expression is taking the variable carPrice and replacing all the commas in the string with nothing and then converting | ||
the string into a number so that it can be used in calculations.*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const movieLength = 8784; // length of movie in seconds | ||
const movieLength = 7784; // length of movie in seconds | ||
|
||
const remainingSeconds = movieLength % 60; | ||
const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
@@ -12,14 +12,22 @@ 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 in this program. They are on lines 1, 3, 4, 6, 7 and 9 | ||
|
||
// b) How many function calls are there? | ||
// there are 2 function calls in this program. They are on lines 9 and 10 | ||
|
||
|
||
// 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 is using the modulus operator (%) to find the remainder when movieLength (8784) is divided by 60. | ||
|
||
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
/* line 4 is calculating the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in | ||
seconds and then dividing that result by 60.*/ | ||
|
||
// e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
/* the variable result represents the total length of the movie in hours, minutes and seconds. A better name for this variable could | ||
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. Is it clear what the difference is between movieDuration and movieLength? Could I understand the difference by quickly reading these two variable names? 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 really — they could easily be confused, especially in a larger codebase where someone is scanning quickly. we can change movieDuration to something like formattedmovieDuration |
||
be movieDuration.*/ | ||
|
||
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
// yes this code will work for all values of movieLength as long as the value is a non-negative integer representing the length of a movie in seconds. | ||
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. Are you sure there are no values that might give unexpected or oddly formatted output? 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 will work correctly, but it can produce unexpected or oddly formatted output in terms of readability, especially for values less than 10. Expected value: 02:09:44 |
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.
Are you sure these numbers are correct? How are you identifying function calls?
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.
Hello,
Thank you for the feedback.
there are 5 function calls and, they are on lines 4, 5, and 10
function calls: replaceAll(), replaceAll(), Number(), Number(), console.log()