Skip to content

Commit 7309397

Browse files
committed
sprint-1 exercies has been completed
1 parent 37da673 commit 7309397

File tree

9 files changed

+50
-7
lines changed

9 files changed

+50
-7
lines changed

Sprint-1/1-key-exercises/1-count.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
// is assignment it takes the variable vlue, which is 0 and add 1.
8+
// // Since count was initially 0, this becomes: count = 0 + 1, so count now holds the value 1.

Sprint-1/1-key-exercises/2-initials.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let lastName = "Johnson";
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

88
let initials = `${firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0)}`;
9-
console.log(typeof(initials)) //==> CKJ
9+
// console.log(initials) ==> CKJ
1010

1111
// https://www.google.com/search?q=get+first+character+of+string+mdn
1212

Sprint-1/1-key-exercises/3-paths.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ const dir = filePath.slice(0,lastSlashIndex)
2222

2323
const lastDoutIndex = base.lastIndexOf(".")
2424
const ext = base.slice(lastDoutIndex)
25-
console.log(ext)
2625

2726
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const minimum = 1;
22
const maximum = 100;
33

4-
const num = Math.floor(0.999 * (maximum - minimum + 1)) + minimum;
4+
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
77
// Try breaking down the expression and using documentation to explain what it means

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
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?
3+
// we could add a Single-line comment // .or Multi-line comment /* */
4+
// Now JavaScript will ignore those lines, and they will not affect our program.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
// const age = 33;
44
let age = 33;
55
age = age + 1;
6+

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ 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-
// 3 functions in lines 4, 5 and 10
15+
// 5 functions in lines 4, 5 and 10
1616

1717
// 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+
// SyntaxError: missing ) after argument list is Missing comma between arguments
1819

1920
// c) Identify all the lines that are variable reassignment statements
21+
// Line 4 :carPrice = Number(carPrice.replaceAll(",", ""));
22+
// Line 5:priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
2023

2124
// d) Identify all the lines that are variable declarations
25+
// Line 1: let carPrice = "10,000";
26+
// Line 2: let priceAfterOneYear = "8,543";
27+
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
28+
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
2229

2330
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+
// removes all commas from the string "10,000", making it "10000". and Number(...): converts the resulting string "10000" to a number type 10000.
32+
// so the purpose is to convert a comma-formatted string into a usable numeric value for mathematical operation.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
1313

14-
// a) How many variable declarations are there in this program?
14+
// a) How many variable declarations are there in this program
15+
// 6 variable declared
1516

1617
// b) How many function calls are there?
18+
// 1 function in line 10
1719

1820
// c) Using documentation, explain what the expression movieLength % 60 represents
21+
//The remainder (%) operator returns the remainder
22+
// so is divide movieLength by 60 and return the remainder."
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2024

2125
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+
//First, it takes away the extra seconds that don't make up a full minute.
27+
// Then it divides the remaining seconds by 60 to figure out how many complete minutes are in the movie.
2228

2329
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+
// formattedTime
2431

2532
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
33+
// Yes but not all ,because It handles converting seconds into minutes and hours using integer division and modulus.But with negative integers dose not work correcly
34+
//And does not pad single-digit values with zeroes as wll, It will return something like 2:4:7 instead of 02:04:07, which is not a standard time format.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ 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+
// Initializes a string that represents an amount in (pence), ending with a `"p"` to signify pence (e.g., `"399p"` = 399 pence).
29+
30+
//2- const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
31+
// this Removes the trailing "p" from the string.so it is substring(0, penceString.length - 1)
32+
// takes all characters except the last. for example For "399p", this returns "399".
33+
34+
// 3-const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
35+
// Pads the number with leading zeros to ensure it is at least 3 digits long. so it helps normalise values like "5" → "005" and "99" → "099".
36+
37+
// 4 const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
38+
// Extracts the pounds from the padded string.so it takes all digits except the last two.
39+
//For "399", this gives "3" → meaning 3 pounds.
40+
41+
//5- const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
42+
// Extracts the last two digits for pence and pads them if necessary.
43+
// substring(length - 2) takes the final 2 characters.
44+
// padEnd(2, "0") ensures the pence string is exactly 2 digits. transfer to two-digit formatting for pence 5 => "05".
45+
46+
//6- console.log(`£${pounds}.${pence}`);
47+
//this log the final formatted string in pounds and pence using a template literal.
48+
// For "399p", output is: £3.99

0 commit comments

Comments
 (0)