Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
// Line 3 takes the initial value of count and adds 1 to it
// the = "count + 1 rewrites the count variable to the newly calculated value"
6 changes: 3 additions & 3 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 = ``;

// https://www.google.com/search?q=get+first+character+of+string+mdn
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: 10 additions & 4 deletions Sprint-1/1-key-exercises/3-paths.js
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice!
almost correct!
Please confirm that one of them is missing a "/"

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
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 firstSlashIndex = filePath.indexOf("/");
const dir = filePath.slice(firstSlashIndex + 1, lastSlashIndex - 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Almost correct, Check the range


// https://www.google.com/search?q=slice+mdn
const lastdotindex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastdotindex);

console.log(`The base part of ${filePath} is ${base}
The dir is ${dir}
and the ext is ${ext}`);

// https://www.google.com/search?q=slice+mdn
5 changes: 3 additions & 2 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const minimum = 1;
const maximum = 100;
const minimum = 80;
const maximum = 83;

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

// 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
console.log(num);
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?

comment them out!*/
5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// 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);

// it needed to be a variabal not a constant
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}`);
// the constant was declared after the sentence that used it
7 changes: 5 additions & 2 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 cardNumber = "4533787178994213";
const last4Digits = cardNumber.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


//it will not work because the cardNumber is a number and not a string so it cant use the slice method
19 changes: 17 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The specific time period was not taken into account; it is recommended to conduct some conversion tests for different time periods.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

12:xx PM should still be 12:xx
12:xx AM should be 00:xx

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

another thing is

13.00 should use ":" not "."

Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
//const twelveHourClockTime = "20:53";
//const twentyFourHourClockTime = "08:53";

//variable names can't start with a number

// the times are in the wrong places ie:-20:53 is not a twelve hour time and as they are const they cant be directly changed

let twelveHourClockTime = "20:53";
let twelthHour = twelveHourClockTime.substring(0, twelveHourClockTime.length -3);
if (twelthHour >12) {twelthHour = twelthHour - 12};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

weird indentation

let twelthMinutes = twelveHourClockTime.substring(2, twelveHourClockTime.length)

let twentyFourHourClockTime = "08:53";


console.log(`${twelthHour}${twelthMinutes}`);
console.log(twentyFourHourClockTime);
11 changes: 10 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 @@ -13,10 +13,19 @@ 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

// carPrice = Number(carPrice.replaceAll(",", ""));
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
// both use a call to read the string as a number and to replaceAll the comas with a null value


// 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?
// the error is on line 5 there should be a coma after the "," to make the change

// c) Identify all the lines that are variable reassignment statements
// lines 5 and 6 reassign the variables from the string to a number so that we can do a calculation on it

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// it is changing the string "10,000" to a number and removing the comma so it can be used in the calculation
9 changes: 7 additions & 2 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 4; // length of movie in seconds
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why change the length from 8784 to 4

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i was trying a bunch of different values to see how it would handle smaller Numbers have changed it back to the original value now tho


const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,19 @@ 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?
// there are 6 declarations
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Which six?


// b) How many function calls are there?

// 0
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// it divides the first operand (number) by the second operand and returns the remainder

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// line 4 subtracts the remaining seconds so the we can work with the whole Minutes

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// result gives us a string literal with the results of the calculation perhaps a better name would be runLength or watchTime

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// i have went from high (2254:56:54) to low (0:1:24) and it seems to work for any number.
27 changes: 20 additions & 7 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const penceString = "399p";
const penceString = "392p";

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
); //39772

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //39772
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
); // 397

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.padEnd(2, "0"); // 72

console.log(`£${pounds}.${pence}`);
console.log(`£${pounds}.${pence}`); // 397.72

// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand All @@ -24,4 +24,17 @@ 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 to 6.const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
// removes the (p) at the end determined by removing the sudstring at the total length of the string -1

// 8.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// makes sure the string is at least 3 characters long and if it is not it padds it with "0"

// 9.const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2);
// gets the ammout of pounds by making a sub string that starts at the firts character (0) to the paddedPenceNumberString length -2 to exclued the last 2 characters (the p)

// 10.
// 18.console.log(`£${pounds}.${pence}`);
// gives the console the result using a string literal
5 changes: 4 additions & 1 deletion Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ Let's try an example.

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 appered saying 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 give a pop up eith a text input
What is the return value of `prompt`?
the return is what is entred into the text input
Comment thread
mjm-git185 marked this conversation as resolved.
Outdated
7 changes: 6 additions & 1 deletion 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] }
Now enter just `console` in the Console, what output do you get back?
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}assert: ƒ assert()clear: ƒ clear()context: ƒ context()count: ƒ count()countReset: ƒ countReset()createTask: ƒ createTask()debug: ƒ debug()dir: ƒ dir()dirxml: ƒ dirxml()error: ƒ error()group: ƒ group()groupCollapsed: ƒ groupCollapsed()groupEnd: ƒ groupEnd()info: ƒ info()log: ƒ log()memory: MemoryInfo {totalJSHeapSize: 12700000, usedJSHeapSize: 10000000, jsHeapSizeLimit: 2330000000}profile: ƒ profile()profileEnd: ƒ profileEnd()table: ƒ table()time: ƒ time()timeEnd: ƒ timeEnd()timeLog: ƒ timeLog()timeStamp: ƒ timeStamp()trace: ƒ trace()warn: ƒ warn()length: 0name: "warn"arguments: (...)caller: (...)[[Prototype]]: ƒ ()[[Scopes]]: Scopes[0]Symbol(Symbol.toStringTag): "console"[[Prototype]]: Object[[Prototype]]: Object

Try also entering `typeof console`
'object'

Answer the following questions:

What does `console` store?
the console stores objects

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
the . denotes what kind of object the console is being told to use and what to do with the data it has been given