File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- This is just an instruction for the first activity - but it is just for human consumption
2- We don 't want the computer to run these 2 lines - how can we solve this problem?
1+ // This is just an instruction for the first activity - but it is just for human consumption
2+ // We don't want the computer to run these 2 lines - how can we solve this problem?
Original file line number Diff line number Diff line change 11// trying to create an age variable and then reassign the value by 1
22
3- const age = 33 ;
3+ let age = 33 ;
44age = age + 1 ;
Original file line number Diff line number Diff line change 11// Currently trying to print the string "I was born in Bolton" but it isn't working...
22// what's the error ?
33
4- console . log ( `I was born in ${ cityOfBirth } ` ) ;
54const cityOfBirth = "Bolton" ;
5+ console . log ( `I was born in ${ cityOfBirth } ` ) ;
Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
1+ const cardNumber = " 4533787178994213" ;
22const last4Digits = cardNumber . slice ( - 4 ) ;
33
44// The last4Digits variable should store the last 4 digits of cardNumber
Original file line number Diff line number Diff line change 1- const 12 HourClockTime = "8:53pm" ;
2- const 24 hourClockTime = "20:53" ;
1+ const twelveHourClockTime = "8:53pm" ;
2+ const twentyFourhourClockTime = "20:53" ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ let carPrice = "10,000";
22let priceAfterOneYear = "8,543" ;
33
44carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
5+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
66
77const priceDifference = carPrice - priceAfterOneYear ;
88const percentageChange = ( priceDifference / carPrice ) * 100 ;
Original file line number Diff line number Diff line change @@ -12,14 +12,25 @@ console.log(result);
1212// For the piece of code above, read the code and then answer the following questions
1313
1414// a) How many variable declarations are there in this program?
15+ // Answer: 6
1516
1617// b) How many function calls are there?
18+ // Answer: 1 (console.log(result))
1719
1820// c) Using documentation, explain what the expression movieLength % 60 represents
1921// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22+ // Answer: It returns the remainder after movieLength is divided by 60.
23+ // This gives the number of seconds left over after converting to minutes.
2024
2125// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+ // Answer: It subtracts the remaining seconds from the total seconds,
27+ // then divides by 60 to calculate the total whole minutes.
2228
2329// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+ // Answer: It represents the movie duration in hours:minutes:seconds.
31+ // A better name could be formattedTime or movieDuration.
2432
2533// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+ // Answer: It works for most values, but it does not always display
35+ // the time in the standard format because single-digit minutes or
36+ // seconds are not padded with a leading zero (for example, 5 instead of 05).
Original file line number Diff line number Diff line change @@ -25,3 +25,21 @@ console.log(`£${pounds}.${pence}`);
2525
2626// To begin, we can start with
2727// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
29+ // 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1):
30+ // Removes the "p" from the end of the string, leaving only the number (e.g. "399").
31+
32+ // 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
33+ // Ensures the number has at least 3 digits by adding leading zeros if necessary.
34+ // For example, "5" becomes "005".
35+
36+ // 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
37+ // Takes all but the last two digits to get the pounds part.
38+
39+ // 5. const pence = paddedPenceNumberString
40+ // .substring(paddedPenceNumberString.length - 2)
41+ // .padEnd(2, "0"):
42+ // Takes the last two digits as the pence part and makes sure it has two digits.
43+
44+ // 6. console.log(`£${pounds}.${pence}`):
45+ // Prints the final price in pounds and pence, for example "£3.99".
You can’t perform that action at this time.
0 commit comments