Skip to content

WM | ITP-Jan25 | Hatef Eidi | Module Strcturing and Testing Data | Sprint-1 #263

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9dfbf61
Added new file
HatefEidi Feb 4, 2025
2ae38e4
Added new file
HatefEidi Feb 4, 2025
f4fdf3c
Sprint-1 Initials retrieving
HatefEidi Feb 5, 2025
5bbeaa1
count-Sprint-1 Answer
HatefEidi Feb 5, 2025
04e19e6
Initials-Sprint1-Answer
HatefEidi Feb 5, 2025
26ed136
Paths-Sprint1-Answer
HatefEidi Feb 5, 2025
5302827
random-Sprint1-Answer
HatefEidi Feb 5, 2025
9b1a1cb
modified-initials-sprint1-Answer
HatefEidi Feb 5, 2025
61dbd1b
Comments-Sprint1-Answer
HatefEidi Feb 5, 2025
1a13889
const or let? Answer
HatefEidi Feb 5, 2025
70b0824
referrence Error-Sprint 1- Answer
HatefEidi Feb 5, 2025
1848c74
slice only for strings and array- sprint 1-Answer
HatefEidi Feb 5, 2025
e4d0f87
no numeric values for variables' name-sprint 1-Answer
HatefEidi Feb 5, 2025
dffe519
Percentage Change-Sprint1- Answer
HatefEidi Feb 6, 2025
110186e
Modified Percentage Change- Sprint 1
HatefEidi Feb 6, 2025
5697536
time format-Sprint 1- Answer
HatefEidi Feb 6, 2025
22e82d7
to pounds-Sprint1- Answer
HatefEidi Feb 6, 2025
28e796a
Modified-Not using numeric values in declaration-sprint 1
HatefEidi Feb 6, 2025
83efda8
Answer to object-Sprint1
HatefEidi Feb 6, 2025
b5c7e0f
Chrome Alert and Prompt-Sprint1-Answer
HatefEidi Feb 7, 2025
e07ec38
math.random() exploration
HatefEidi Feb 18, 2025
6c29b81
Naming Variables
HatefEidi Feb 18, 2025
6424450
Choosing the bast variable name- remainingDisplayDisplayTime
HatefEidi Feb 18, 2025
1ebe900
The out-put of prompt
HatefEidi Feb 18, 2025
6dc8e67
Accessing a function within an object using: object.function() approach
HatefEidi Feb 18, 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
3 changes: 3 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,6 @@ 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


//Answer: it's adding one to the value of Variable count which is 0, in line 3 the value of count changes to 1
8 changes: 7 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,13 @@ 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)}`;



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

console.log(initials);
12 changes: 10 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,18 @@ const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);



const dir = filePath.slice(0,lastSlashIndex);
const ext =filePath.slice(filePath.lastIndexOf(".")+1);

console.log(ext);
console.log(dir);

// 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 = ;
// const ext = ;

// https://www.google.com/search?q=slice+mdn
11 changes: 11 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,14 @@ 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



//Answer (before running the code):
// I believe a random number will be multiplied by 100 and added by 1 so will have 101, 201, 301, 401, 501.....
//maximum which is 100 minus minimum which is 1 and added to 1 will result to 100, 100-1+1=100, and it will be multiplied to 100 and added to minimum which is 1.

console.log(num);

//Answer (After running the code):
//Math.random unlike my expectations doesn't produce an integer, it produced a random Floating number between 0 and 1, so we get answer in range of 1 - 100
7 changes: 5 additions & 2 deletions 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?
// 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 should comment them out, in VS Code the shourtcut is cntrl + c, cntrl + k. the symple of commenting out for each coding language differs and computers don't execute the lines that are commented out
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

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

console.log(age);

//In this case we cann't use const variable if we want to change its value later on, so it should be let
4 changes: 3 additions & 1 deletion 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}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);

//The error was Referrence Error which is cause by using a variable before declaring it. JavaScript reads from top to bottom, so we have to declare the variable first and the use it. I moved the cityOfBirth variable one line above the console.log funciton
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const lastFourDigits = String(cardNumber).slice(-4);

console.log(lastFourDigits);

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


//Prediction and explaination:
//index value is only for string and array data types, in this case it throws an error since cardNumber holds a number not string or arrray.
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";

//Answer: we can declare or name our variables using numeric values, but we can't start with a number, so we can't name our variables as 20:53 or 08:53
// Furthermore, the variable's name doesn't match the content of the variables and the naming should be opposite, to match the content of the values.
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 @@ -12,11 +12,18 @@ 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
// 3 function calls: Numbers(), variable.replaceAll(), and console.log

// 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?
//On Output and Problems Console tabs, it said on line 5, a comma was missing, after comparing with the upper line that has the same function, I added a comma to separate the arguments that were passed to the function.


// c) Identify all the lines that are variable reassignment statements
// Line 4 and 5, because we are assigning a new value to the variables that are already declared in the previous line (1 and 2)

// d) Identify all the lines that are variable declarations
// line 1,2,7,8


// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//Number convert the current values ,in both variables declared in line 1 and 2, to number after removing comma from the values
9 changes: 9 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ 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?
// Answer: 6 variables: line 1,3,4,6,7,9, wherever there is const or let word

// b) How many function calls are there?
// Answer: only 1: Console.log

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
//Answer: the expression will divide movieLength which is second to 60 and extract the REMAINDER of the operation. The remainder in this case can have a range of values between 0-59s


// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//Answer: in line four we are subtracting the remainder of movieLength divided by 60 to make a divisible number by 60, because we want to know how many minutes the movieLength is in minute not second unit and minutes should be integer not float.


// e) What do you think the variable result represents? Can you think of a better name for this variable?
// Answer: the length of the movie in the following format: hr:min:sec, movieLength would be an appropriate alternative for this variable, however since we already have a variable with the same name and const type which the value cannot be changed, "remainingDisplayTime" is the best name that reaches my mind.


// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//Answer: Yes I believe it would work for all the values, since we divide the movieLength by 60 one time to get the minutes and two time to get the hours, if we have a 0 second movie the calculation would still run without throwing an error since 0 is not in the denominator and is numerator.
5 changes: 5 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,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): extract every characters in penceString variable except the last one (penceString,length -1)
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the number is at least 3 digit long and if not adds 0 before the number not to change the value.
// 4.const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2): extract everything but the last 2 digits (-2) from paddedPenceNumberString variable to get the pound number
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): similar to pound, it extract the last two digits of paddedPenceNumberString to get the pence number, If there’s only one digit, it ensures two digits by adding a trailing zero
// 6. console.log(`£${pounds}.${pence}`): in this line the pound value will be displayed to the user in this format: £ pound. pence
7 changes: 7 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,15 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
A pop-up box will appear with the text of 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?
A pop-up box will appear with the text what is your name? and input text box to let the user type their names
If they press cancel, whether or not they have entered their name in the text box- in the console we will see the 'null' in the next line of the prompt
If they enter their name, and press ok, in the console they can view their name.

What is the return value of `prompt`?
The input of the what is your name pop-up text
Copy link
Contributor

Choose a reason for hiding this comment

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

If you were writing a program that uses prompt() to ask for an input value, how can
your program tell if the user clicked "OK" or "Cancel"?

Copy link
Author

Choose a reason for hiding this comment

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

If they press cancel, whether or not they have entered their name in the text box- in the console we will see the 'null' in the next line of the prompt
If they enter their name, and press ok, in the console they can view their name.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user entered "null" and pressed ok?

Copy link
Author

Choose a reason for hiding this comment

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

it will return the string of null which is the input=> 'null'

If they enter their name, and press ok, in the console they can view their name.
9 changes: 7 additions & 2 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?
undefined if () were typed
ƒ log() { [native code] } if () were not typed

Now enter just `console` in the Console, what output do you get back?
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
object

Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
What does `console` store? some functions that can be called like "log"
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
we are calling assert or log function from console which stores these functions. The "." tells the program to access the console object and call the function log, or assert within console object.
Binary file added prep/Convert.js
Binary file not shown.
2 changes: 2 additions & 0 deletions prep/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log("Hello, this is my JavaScript file!");
console.log("Node.js is executing this file.");