Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 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,5 @@ 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
// is assignment it takes the variable vlue, which is 0 and add 1.
// // Since count was initially 0, this becomes: count = 0 + 1, so count now holds the value 1.
3 changes: 2 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ 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.

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

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

7 changes: 5 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
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)

const lastDoutIndex = base.lastIndexOf(".")
const ext = base.slice(lastDoutIndex)

// https://www.google.com/search?q=slice+mdn
8 changes: 8 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,11 @@ 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)
//num is a random number between the minimum and maximum.
// 1. Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1
// 2. (maximum - minimum + 1) Calculates the range of values, including both ends.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When describing situations like this, instead of "including both ends" or something, I would suggest using a word like "inclusive" or "exclusive". Good explanation, though!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

// For 1 to 100, this is:
// 100 - 1 + 1 = 100
//3- Math.floor() static method always rounds down and returns the largest integer less than or equal to a given number.
// example Math.floor(50.9) = 50
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
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 could add a Single-line comment // .or Multi-line comment /* */
// Now JavaScript will ignore those lines, and they will not affect our program.
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
// const age = 33;
let age = 33;
age = age + 1;

6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
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 ?

console.log(`I was born in ${cityOfBirth}`);
// console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
// Variables declared with (const) (or let) are not accessible before their declaration, even though they are hoisted (set aside in memory).
// // So, when console.log(...) runs, cityOfBirth exists in memory but is not yet initialized, so trying to access it throws an error.
9 changes: 6 additions & 3 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// 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
// .slice() called on a number, and Numbers don’t have string methods like .slice().it will throw an error
// console.log(last4Digits) => TypeError: cardNumber.slice is not a function at Object.
const cardNumber = 4533787178994213;
// const last4Digits = cardNumber.toString;
const last4Digits = cardNumber % 10000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creative solution! Would this still function properly if the card number was 4533787178900003?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank i have updated this one

console.log(last4Digits)
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
// const 12HourClockTime = "20:53";
// const 24hourClockTime = "08:53";
// JavaScript does not allow variable names to begin with a digit. The variable name 12HourClockTime starts with 12,
// which is not valid syntax, and will throw a SyntaxError:

const hourClockTime24 = "20:53";
const hourClockTime12 = "08:53";
12 changes: 11 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,11 +12,21 @@ 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
// 5 functions in lines 4, 5 and 10

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

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

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// removes all commas from the string "10,000", making it "10000". and Number(...): converts the resulting string "10000" to a number type 10000.
// so the purpose is to convert a comma-formatted string into a usable numeric value for mathematical operation.
11 changes: 10 additions & 1 deletion Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ 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?
// a) How many variable declarations are there in this program
// 6 variable declared

// b) How many function calls are there?
// 1 function in line 10

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

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

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

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// 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
//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.
21 changes: 21 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,24 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// Initializes a string that represents an amount in (pence), ending with a `"p"` to signify pence (e.g., `"399p"` = 399 pence).

//2- const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
// this Removes the trailing "p" from the string.so it is substring(0, penceString.length - 1)
// takes all characters except the last. for example For "399p", this returns "399".

// 3-const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// 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".

// 4 const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
// Extracts the pounds from the padded string.so it takes all digits except the last two.
//For "399", this gives "3" → meaning 3 pounds.

//5- const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
// Extracts the last two digits for pence and pads them if necessary.
// substring(length - 2) takes the final 2 characters.
// padEnd(2, "0") ensures the pence string is exactly 2 digits. transfer to two-digit formatting for pence 5 => "05".

//6- console.log(`£${pounds}.${pence}`);
//this log the final formatted string in pounds and pence using a template literal.
// For "399p", output is: £3.99
Loading