Skip to content

London- ITP January | Shohreh Bayat | Structuring and testing data | Week 1 #268

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 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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?
2 changes: 1 addition & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 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}`);

Choose a reason for hiding this comment

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

what was the error can you also explain it please ?

7 changes: 6 additions & 1 deletion 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 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?

Choose a reason for hiding this comment

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

It is important to understand why we got an error in the first place, can you explain what causes the error

// Then try updating the expression last4Digits is assigned to, in order to get the correct value


// In order to get an answer, I need to use something like "console.log" to be able to print it.
6 changes: 4 additions & 2 deletions 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 TwelveHourClockTime = "08:53";
const TwentyfourHourClockTime = "20:53";
console.log(TwelveHourClockTime);
console.log(TwentyfourHourClockTime);
14 changes: 14 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ console.log(`The percentage change is ${percentageChange}`);

// a) How many function calls are there in this file? Write down all the lines where a function call is made

//5 functions
//Number(carPrice.replaceAll(",", ""));
//replaceAll(",", "")
// Number(priceAfterOneYear.replaceAll("," ""))
//replaceAll("," "")
//console.log(`The percentage change is ${percentageChange}`)

// 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. priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

Choose a reason for hiding this comment

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

are you sure "missing )" is the reason behind syntax error ?

// c) Identify all the lines that are variable reassignment statements
//2 times
//carPrice = Number(carPrice.replaceAll(",", ""));
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

// d) Identify all the lines that are variable declarations
//4 times. lines which has Let and const.

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// it removes the "," which is in between the 10,000 and make it "10000", same for "8543"
//Number changes the type of strings to a numbers
8 changes: 7 additions & 1 deletion Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ 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?
//6 variable declaration, all of the lines which starts with const.

// b) How many function calls are there?
// b) How many function calls are there?
//only one function call which is 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
// % is a "Remainder operator"

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// It calculates according to minutes. Initially it takes movie length in seconds and reduces it from remaining seconds, then the answer will be divided to 60 which shows the length of the movie in minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
//It shows the duration of the movie in HH:MM:SS. A better name could be "MovieDuration" or "MovieLength".

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//Yes, the code works for all length of movies from 0 and more. It converts any movie length to HH:MM:SS format.
6 changes: 6 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,9 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
//2. removes P at the end of the 399P to show the numerical part of the string.
//3.Pads the string to ensure it's at least 3 digits long
//4. Extracts the pounds part (the first digit) from the string "3" from "399"
//5.Extracts the pence part (last two digits) and ensures it's always 2 digits long.
//6. Prints it in a format with symbols pounds and pence.

Loading