Skip to content

sprint 1 #345

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ count = count + 1;

// 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
/* count + 1 is evaluated. This takes the current value of count (which is 0) and adds 1 to it, resulting in 1.
The result of the addition (1) is then assigned to the variable count. This overwrites the previous value of count (which was 0) with the new value (1).

So, after line 3 is executed, the variable count will hold the value 1.
*/
/*The
= symbol in this context is the assignment operator. It means "take the value of what is on
the right-hand side and store it in the variable on the left-hand side."
*/
9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ let middleName = "Katherine";
let lastName = "Johnson";

// Declare a variable called initials that stores the first character of each string.
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
// This should produce the string "CKJ", but you must not write the characters C, K,
// or J in the code of your solution.

let initials = ``;


let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

console.log(initials);

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

9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ console.log(`The base part of ${filePath} is ${base}`);
// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable

const dir = ;
const ext = ;

const dir = filePath.slice(0, lastSlashIndex + 1);
const lastDotIndex = base.lastIndexOf(".");
const ext = lastDotIndex > -1 ? base.slice(lastDotIndex) : ""; // Handle cases with no extension

console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);

// https://www.google.com/search?q=slice+mdn
10 changes: 10 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// Try breaking down the expression and using documentation to explain what it means
// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing
console.log(num); // Output the generated random number


/*num represents a random integer between 1 and 100 (inclusive). */

/*Math.random()
This means it can return 0, but it will never return 1.
Think of it as generating a random fraction between 0 and 1. */

/* */
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
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?
in javascript .
// 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?
5 changes: 5 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

const age = 33;
age = age + 1;
/* In JavaScript (and many other languages), const declares a constant,
meaning its value cannot be changed after it's initially assigned. */
let age = 33;
age = age + 1;
console.log(age);
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
// what's the error ?

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
//const cityOfBirth = "Bolton";
/*Always declare your variables (especially const and let)
before you attempt to use them*/
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
4 changes: 4 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ const last4Digits = cardNumber.slice(-4);
// Then run the code and see what error it gives.
// 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
/* we declare cardNumber as number . slice , This function for string */
const cardNumber = 4533787178994213;
const last4Digits = String(cardNumber).slice(-4); // Convert to string first
console.log(last4Digits);
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";
23 changes: 23 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,26 @@ console.log(`The percentage change is ${percentageChange}`);
// d) Identify all the lines that are variable declarations

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
a) carPrice.replaceAll(",", "")
priceAfterOneYear.replaceAll(",", "")
Number()
console.log()
b)
There's a missing comma after the first argument in replaceAll. It should be:
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
c)
carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
d)
let carPrice = "10,000";
let priceAfterOneYear = "8,543";
const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
e)
carPrice.replaceAll(",", ""): This part uses the replaceAll method to
replace all occurrences of the comma (,) within the carPrice string with
an empty string (""). This removes the comma from the
string "10,000",
resulting in the string "10000".

Number(): The Number() function convert the string as Number
26 changes: 26 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,29 @@ console.log(result);
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
a)
result is also a variable declaration, there are six.
b)
There is one function call: console.log(result)

c)
The % symbol is the modulo operator.
the modulo operator returns the remainder of a division.
So, movieLength % 60 calculates the remainder when movieLength is divided
by 60.
d)
movieLength - remainingSeconds: This subtracts the remaining seconds
from the total seconds.
/ 60: this division gives you the total number of whole minutes in the movie.

e)
1)The variable result represents the formatted movie length in hours, minutes, and seconds (HH:MM:SS format).

2)formattedTime or formattedMovieLength.
f)

1)The modulo operator and integer division will handle positive integer values correctly.
2) If movieLength is 0, the code will correctly produce "0:0:0".
3)If movieLength is negative, the modulo operator will return a negative
remainder. While the code might technically run,
the output will not be a correct
32 changes: 31 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,34 @@ console.log(`£${pounds}.${pence}`);
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
/* 1. const penceString = "399p": initialises a string variable with
the value "399p"
2.
const penceString = "399p";:
This line initializes a constant variable named penceString and assigns it the string value "399p". This string represents a price in pence. The const keyword means the variable's value cannot be reassigned later in the program.

const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);:
This line creates a new constant variable called penceStringWithoutTrailingP. It uses the substring() method to extract a portion of the penceString. penceString.length gets the total length of the string (5 in this case). Subtracting 1 gives us 4. substring(0, 4) extracts the characters from index 0 up to (but not including) index 4, effectively removing the last character "p". The result, "399", is stored in penceStringWithoutTrailingP. The rationale is to isolate the numerical part of the pence value.

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");:
This line creates another constant, paddedPenceNumberString. It uses the padStart() method to
pad the penceStringWithoutTrailingP with leading zeros until it reaches a length of 3. If the
string is already 3 or more characters long, no padding is added. In our example, "399" is
already 3 digits, so no padding occurs. The result, "399", is stored in paddedPenceNumberString.
The rationale for padding is to ensure that even single-digit or double-digit pence values are
formatted correctly when converted to pounds and pence (e.g., "9p" becomes "009").

const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);:
This line extracts the pounds portion of the price. paddedPenceNumberString.length - 2 calculates the index
two characters from the end. substring(0, paddedPenceNumberString.length - 2) extracts the
characters from the beginning up to that index.
In our example, paddedPenceNumberString.length is 3,
so paddedPenceNumberString.length - 2 is 1. substring(0, 1) extracts the first character, "3".
The result, "3", is assigned to the pounds constant. The rationale is to separate the pounds from
the pence.

const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");:
This line extracts the pence portion. paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) extracts the last two characters of the padded number string ("99" in our example). The padEnd(2, "0") method ensures that the pence value has at least two digits, adding trailing zeros if necessary. In our case, "99" already has two digits, so no padding is added. The result, "99", is assigned to the pence constant. The rationale is to isolate the pence value.

console.log(£pounds.{pence});: This line uses a template literal (backticks) to create a string that combines the pounds and pence values with a pound symbol and a decimal point. It then uses console.log() to print this formatted string to the console. In our example, it will print "£3.99". This is the final formatted price in pounds and pence.
*/
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> https://programming.codeyourfuture.io/structuring-data/

> [!TIP]
> [!TIP]k
> You should always do the prep work _before_ attempting the coursework.
> The prep shows you _how_ to do the coursework.
> There is often a step by step video you can code along with too.
Expand Down