Skip to content

WEST-MIDLANDS-JAN-ITP|SEGUN FOLAYAN|STRUCTURING AND TESTING DATA|SPRINT1 #428

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 9 commits 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
3 changes: 2 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let count = 0;

count = count + 1;
count = count + 1; // Further note based on feedback => I can also describe this as 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 three adds 1 to the value of count and stores it as count
Copy link
Contributor

Choose a reason for hiding this comment

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

Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.

May I suggest feeding the code to ChatGPT and see how else the code can be described? From time to time you may learn some new programming terms.

Copy link
Author

Choose a reason for hiding this comment

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

The operation count = count + 1 is called increment.

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);

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

14 changes: 11 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ 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);

// https://www.google.com/search?q=slice+mdn
// Extract the file extension part
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);

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

// https://www.google.com/search?q=slice+mdn
7 changes: 7 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ const minimum = 1;
const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
console.log(num);

// In this exercise, you will need to work out what num represents?
// 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
// Math.floor() method always rounds down and returns the largest integer less than or equal to a given number
// Math.random() method returns a floating-point pseudo-random number in the range 0 to less than 1
// Further information based on review:
// what is the use of (maximum-minimum+1) at line 4 => This is to ensure that we get a range of value between maximum and minimum
// what is the use of + minimum at line 4 => To make sure we do not get a number below the minimum
// what is the possible range of value of num => num ranges from 1-100
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? I have added stroke to comment it out.
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 34;
age = age + 1;
console.log(age);
6 changes: 3 additions & 3 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}`);
// what's the error ? const cityofBirth needs to be declared before it can be used.
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);

10 changes: 6 additions & 4 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
//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?
// Before running the code, make and explain a prediction about why the code won't work- This is because .slice is a string method.
// Then run the code and see what error it gives-It says cardNumber.slice is not a function.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different? Like I mentioned .slice is string method.
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
7 changes: 6 additions & 1 deletion 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 24hourClockTime = "08:53"; // This should be correctly written as "08:53 PM" in the 24 hour format

// Further information based on review:
// line 1 should be written as const twelveHourClockTime = "20:53",
// line 2 should be written as const twentyFourHourClockTime = "08:53"
//
14 changes: 7 additions & 7 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ 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;

console.log(`The percentage change is ${percentageChange}`);

// Read the code and then answer the questions below
// 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
// a) How many function calls are there in this file? Write down all the lines where a function call is made: Thete are 5 functions- 2 on line 4, 2 on line 5 and 1 on line 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?
// 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? line 5, a comma is needed

// c) Identify all the lines that are variable reassignment statements
// c) Identify all the lines that are variable reassignment statements- line 4 and line 5

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - What is the purpose of this expression? This expression removed the comma in the number and convert the string into a number
19 changes: 13 additions & 6 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const movieLength = 8784; // length of movie in seconds
//const movieLength = 100;

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -11,15 +12,21 @@ 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

// b) How many function calls are there?
// b) How many function calls are there? 1

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// % is the module operator, which calculated the remainder of the division of movieLength by 60
// Further information based on feedback: This expresss represents the seconds left over when all the full minutes of the movie has been subtracted from total time.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? Computes the the difference between movielength and remaining minutes. And divides this by 60.
Copy link
Contributor

Choose a reason for hiding this comment

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

Your description is a literal translation (in English) of (movieLength - remainingSeconds) / 60; the description does not give any new information about the calculated value.

Can you describe the value the expression calculates?

Copy link
Author

Choose a reason for hiding this comment

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

This calculates the number of full completed minutes the movie takes


// e) What do you think the variable result represents? Can you think of a better name for this variable?
// e) What do you think the variable result represents? Can you think of a better name for this variable? It gives the time of the movie in hours, minutes and seconds
// Further Information based on feedback => variable counld be moviedurationHMS

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer. It does work for all number inputs.
// f) For example, movieLength of 100 gives 0:-1:-40 and movieLength of 8784 gives 2:26:24

//Further information based on feedback: This is a mistake, it should be 0:1:40
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); Removes the p from the string. Result=399
// 3 const paddedPenceNumberString=penceStringWithoutTrailingP.padStart(3,"0"):This ensures that the pence value has at least three digits. It can add three leading zeros if necessary
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length-2); Extracts the pound part of rhe value.
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length-2).padEnd(2,"0"); Extracts the pence portion of the value
// 6. Computes out the final number in pounds and pence.
11 changes: 7 additions & 4 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ Just like the Node REPL, you can input JavaScript code into the Console tab and
Let's try an example.

In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
What effect does calling the `alert` function have? This prints Hello world to the console: The browser displays "Hello world!" in a pop up window Correction: it displays "Hello world!" in a pop up window. Not to the console.

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?
What is the return value of `prompt`?
What effect does calling the `prompt` function have? It displays a dialog box that allows the user to give an input
What is the return value of `prompt`? It displays a dialog box.
Correction: prompt returns the string input typed in by the User.
If the user clicks okay, it returns the string typed in by the user.
If the user clicks Cancel, the return value in null.
11 changes: 7 additions & 4 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ 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?
What output do you get? f log(){[native code]}

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

Try also entering `typeof console`
Try also entering `typeof console` This gives 'object'

Answer the following questions:

What does `console` store?
What does `console` store? It is used for logging information. It has its own methods that help to log information. It also help to debuggi
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
console.log outputs a message to the console.
If the assertion is false, it logs an error message to the console.