Skip to content

Commit c8de3b5

Browse files
author
Enice-Codes
committed
completed all three excerises in this sprint
1 parent 7f49f8b commit c8de3b5

13 files changed

Lines changed: 67 additions & 11 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b31a586bf20de09330f37bcf5d708e5ecd67f45b

Sprint-1/1-key-exercises/4-random.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1313

1414
// It will help to think about the order in which expressions are evaluated
1515
// Try logging the value of num and running the program several times to build an idea of what the program is doing
16+
console.log(num);

Sprint-1/2-mandatory-errors/0.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
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?
2+
We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
// we can use //to comment out the lines of code we don't want to run.
5+
6+
//his is just an instruction for the first activity - but it is just for human consumption
7+
//We don't want the computer to run these 2 lines - how can we solve this problem?

Sprint-1/2-mandatory-errors/1.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;
5+
console.log(age);

Sprint-1/2-mandatory-errors/2.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
// the error is that the variable cityOfBirth is being use in the console.log statement before it is declared with let or const unlike var.
8+

Sprint-1/2-mandatory-errors/3.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
32

3+
const last4Digits = String(cardNumber).slice(-4);
4+
5+
6+
console.log(last4Digits); // "4213"
7+
8+
9+
let prediction = " because of the lack of slice method available for numbers,I predict that the code will throw an error. the cardNumber variable is a number, and slice is a method that can only be used on strings or arrays.";
10+
slice is a method that can only be used on strings or arrays."
11+
12+
//.slice () works on arrays and strings
13+
14+
// i ran the code the error i got was excatly as predicted.
15+
416
// The last4Digits variable should store the last 4 digits of cardNumber
517
// However, the code isn't working
618
// Before running the code, make and explain a prediction about why the code won't work

Sprint-1/2-mandatory-errors/4.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const twelveHourClockTime = "8:53pm";
2+
// the code having an error because the variable is not named correctly,has to be twelvehourclocktime instead of 12hourclocktime.
3+
const twentyFourHourClockTime = "20:53";
4+
// the code having an error because the variable is not named correctly,has to be twentyfourhourclocktime insted of 24hourclocktime.
5+

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,11 +12,19 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15+
//one function call in line 4 ,5
1516

1617
// 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?
18+
// there seem to be no error when running the code.
1719

1820
// c) Identify all the lines that are variable reassignment statements
21+
// line 4 and 5
1922

2023
// d) Identify all the lines that are variable declarations
24+
// 1,2,7,8
2125

2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
28+
// The expression `Number(carPrice.replaceAll(",", ""))` is performs two operations. it uses the `replaceAll` method to remove all commas from the string `carPrice`, effectively converting it from a formatted string o a plain number string.
29+
//Then, it converts that resulting string into a number using the `Number()` function.
30+
//The purpose of this expression is to convert a formatted price string into a numerical value that can be used for calculations.

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@ const remainingMinutes = totalMinutes % 60;
77
const totalHours = (totalMinutes - remainingMinutes) / 60;
88

99
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10-
console.log(result);
10+
11+
1112

1213
// For the piece of code above, read the code and then answer the following questions
1314

1415
// a) How many variable declarations are there in this program?
16+
// 6 variables in total: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
1517

1618
// b) How many function calls are there?
19+
// there are 3 function calls in line 4,7 and 9
1720

1821
// c) Using documentation, explain what the expression movieLength % 60 represents
1922
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
25+
// it means that the movie hour is being calculated. totalminutes minus remainingseconds divided by 60.
2326
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
27+
// the variable result represents the total length of the movie in hours and minutes.
28+
//Better name is MOvieTime.
2529
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
30+
// Yes, this code will work for all values because it is using the modulus operator to calculate the remaining seconds and is using division to calculate the total hours.
31+
// The code will correctly handle any length of movie in seconds and convert it to the appropriate format.
32+

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
// 1. const penceString = "399p": // the "399p"represents the amount in pence.
28+
// initializes a string variable with the value "399p"
29+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): // the trailing 'p'has been removed from the string to isolate the numeric value.
30+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): // ensures that the numeric value has at least three digits by padding with leading zeros .
31+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): // extracts the pounds portion of the string by taking all but the last two characters.
32+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): // extracts the pence portion of the string by taking the last two characters and ensures it has two digits by padding with trailing zeros .
33+
// 6. console.log(`£${pounds}.${pence}`): // outputs the final formatted price in pounds and pence to the console, prefixed with the pound symbol (£).

0 commit comments

Comments
 (0)