Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
65fe894
Answered comment for count update in exercise -1
ahmadehsas Jun 16, 2025
c7a00b7
completed initials exercise using string indexing
ahmadehsas Jun 16, 2025
1891614
Add dir and ext veriables to extract directory and extension from fil…
ahmadehsas Jun 16, 2025
a9f60fe
Add explanation of how num is calculated as a random number between m…
ahmadehsas Jun 17, 2025
ac2cdb5
fixed error by changing const to let for age reasignment.
ahmadehsas Jun 17, 2025
3966773
Fixed reference error by declaring cityOfBirth before using it.
ahmadehsas Jun 17, 2025
9328618
fixed typeEroor by converting number to string before slicing last 4…
ahmadehsas Jun 17, 2025
4207936
Fixed syntax error by moving numbers after the words or spell the nu…
ahmadehsas Jun 17, 2025
bf8a890
Fixed syntax error in replaceAll for priceafteroneyear, and answer in…
ahmadehsas Jun 17, 2025
34c796a
Added Answers to the questions about time conversion exercise. Added …
ahmadehsas Jun 17, 2025
b83f152
Added breakdown of code converting pence string to pound format.
ahmadehsas Jun 17, 2025
254cd3f
completed chrome console exercise using prompt and alert
ahmadehsas Jun 17, 2025
7a97c4f
investigate console object and dot notation in java script using chro…
ahmadehsas Jun 18, 2025
567e88f
Answered the question of line-9.
ahmadehsas Jul 12, 2025
2f51f5b
Replaced the word Const line to Const Variable on 9.
ahmadehsas Jul 12, 2025
838110d
Answered the question on line 36 & 37.
ahmadehsas Jul 12, 2025
832af0e
Answered the questio on line 23 & 24.
ahmadehsas Jul 12, 2025
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
5 changes: 5 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,8 @@ 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
// line 3 increases the value of count by 1.
// the "=" operator assigns the result of "count + 1" back to the variable count.
// Can you find out what one-word programming term describes the operation on line 3?
// The one word term is "increment".
// increment means increasing the value of a variable by 1.
7 changes: 6 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,12 @@ 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[0] + middleName[0] + lastName[0];
console.log(initials)
// fistName[0] gets the first character of the string "Creola" C
// middleName[0] gets the second character of the name "Katherine" K
// lastName[0] gets the third character of the name "Johnson" J


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

6 changes: 4 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,9 @@ 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 ext = base.slice(base.lastIndexOf("."));
// dir uses slice(lastSlashIndex) to get everything before the last slash
// ext used base.slice(base.lastIndexOf(".")) to get .txt

// 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

// The variable "num" stores a random whole number between 1 and 100.
// The expression works as follows:
// 1: Math.random() generates a decimal 0 to 1 (not including 1)
// This decimal is multiplied by (maximum - minimum + 1) which gives a number between 0 and 99.999.
// Math.floor() then rounds this down to a whole number between 0 to 99.
// Adding "minimum" shifts the result so the final number is between 1 to 100.
// for this reason num changes every time when you run the program always gives the number between 1 to 100.
4 changes: 4 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,7 @@

const age = 33;
age = age + 1;

// Error: The variable const for the "age" value can not be reassigned
// const means "constant" once assigned, it can not be changed.
// to fix this error, we use "let" instead of "const" to declare the age variable.
4 changes: 4 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// Reference error:can not access "cityOfBirth" before initialization
// in this code the variable "cityOfBirth" is used before it is been declared"
// solution: Move the const variable above the console.log
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits);

// 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
// TypeError: cardNumber.slice is not a function. it was not the error i predicted, and the difference is that i predicted that the code is correct just add console.log variable.
// How to fix this error: first convert number "toString", then use .slice(-4);.
// The "toString()" method converts number to string.
// java script has trouble with large number so in this case we add the number in string("").
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// syntax error: java script does not allow variable names to start with a number as in above examples: "12HourClockTime", "24hoursClockTime".
// The value does not match in both 24hour and 12hour formats.
// Solution: move the numbers after the words or spell the numbers out.
// the variables should be named like this: const hourClockTime12 = "08:53";, const hourClockTime24 = "20:53";.
// Or like spell the number out: const twelveHourClockTime = "08:53"; , const twentyFourHourClockTime = "20:53";.
9 changes: 8 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 @@ -20,3 +20,10 @@ 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?

// Answer a: 1: carPrice.replaceAll(",", "")- line-4, 2:Number(...)- line-4, 3: priceAfterOneYear.replaceAll(",","")__line-5, 4: Number(...)__line-5, 5: console.log(...)__line-10.
// Answer b: the line 5 has an error, the second replaceAll is missing a comma between the two arguments. to fix this problem add a comma between the two arguments.
// Answer c: line 4 and 5 are variable reassignments.
// Answer d: line 1,2,7 and 8 are variable declarations.
// Answer e: 1: carPrice.replaceAll(",", "")) replaces all commas in "10,000" in an empty string "10000". 2: Number("10000") converts the string "10000" into a number 10000.
// and the purpose of this expression is to clean the price string by removing commas and convert it into a number.
8 changes: 8 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,11 @@ 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

// Answer a: There are 6 variable declarations in this program: movieLength, remainingSeconds,totalMinutes,totalHours,remainingMinutes, and result.
// Answer b: There is only one function call "console,log(result);".
// Answer c: The expression movieLength % 60 uses the modules operator (%) which returns the remainder after dividing movieLength by 60.
// This tells us how many remainder seconds are left after converting the total time into full minutes.
// Answer d: This line calculates the total number of complete minutes in the movie after removing the leftover seconds. in first subtract the remaining seconds then divide the rest by 60 to convert seconds by minutes.
// Answer e: result stores the formatted time in hours,minutes,seconds. A better name for this variable formattedTime,durationString,timeInHMS.
// Answer f: yes, it works for all non negative integer values of movieLength
13 changes: 12 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,15 @@ 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": initializes a string variable with the value "399p"

// 2: "const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1)"__ Removes the trailing "p" character.
// substring(0,penceString.length - 1) this code gets all characters except the last one. so "399p" becomes just"399".
// 3: const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") Ensures the pence string that has at least 3 digits, by padding it in left with "0" if needed for example: 399 stays 399 or 7 would become 007.
// 4: const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2) Extracts the pound portion (except the last two one) __ "399"-"3"(pounds)
// 5: const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") Gets the last two digits as the pence part. for example: "399"__"99"(pence)
// padEnd(2, "0") ensures at least two digits for pence.__eg: "3"_"30".
// 6: console.log(`£${pounds}.${pence}`) logs the full formatted price in pounds and pence.__eg:for "399P" pounds"3" pence"99" and the result is __ "3.99"
// Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
// In other words, do we really need .padEnd(2, "0") in this script?
// Yes, we need `.padEnd(2, "0")` to ensure the penceString is always at least two digits long.
10 changes: 10 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
A popup appears with the message ("Hello world!")

Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`.

What effect does calling the `prompt` function have?
It opens a popup asking for the user’s name, and lets the user type something.
What is the return value of `prompt`?
A string that contains what the user typed (e.g. “Ahmad”).

If we were writing a program that uses prompt() to ask for an input value, how could
the program check if the user clicked "OK" or "Cancel"?

If the user clicks **OK**, it returns the string they typed, even an empty string when there is nothing written.

If the user clicks **Cancel**, it returns null.
5 changes: 5 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ In this activity, we'll explore some additional concepts that you'll encounter i
Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
ƒ log() { [native code] } this output i got when i entered the 'console.log' this function is named 'log'.

Now enter just `console` in the Console, what output do you get back?
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} it contains many functions, we can use it for logging and debugging.

Try also entering `typeof console`

Answer the following questions:

What does `console` store?
The "console" stores the collection of functions used for logging and debugging your java code.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
these are using dot notation, console is an object and log and assert are methods(functions).
dot means access a property or method that belongs to an object.
Loading