Skip to content
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
1 change: 1 addition & 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,4 @@ 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 is reassigning the variable count to a new value.Taking it current value adding 1 to it and storing the result back into count.
2 changes: 1 addition & 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,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 = ``;
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

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

9 changes: 7 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,12 @@ 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 lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex);




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



//Math.random() returns a random number/ decimal number between 0 (inclusive), and 1 (exclusive).

//Math.random() always returns a number lower than 1.

// * (maximum - minimum + 1) multiplying by this is to give a range of possible values.

// adding the minimum at the end is to give a range value between the minimum and maximum inclusive.

// Math.floor usually rounds the number down to the nearest integer.

console.log (num); // first print is 24
console.log (num); // second print 3
console.log (num); // third print is 17
console.log (num); // fourth print is 70
console.log (num); // fifth print is 7
11 changes: 9 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
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.

//SyntaxError: Unexpected identifier 'is' that was the error after i ran node.
// I think javascript is trying run them word for word and found is in an unfamiliar place.
// could also be that its trying to run is as a code which is not correct.

/* To make this correct we can add a double line(//) before the statement to make it a single line comment,
or we can add a line and asterisk before and after to make it a double line comment */
14 changes: 14 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,17 @@

const age = 33;
age = age + 1;

//TypeError: Assignment to constant variable.
// here we already have a variable constant age=33, now we are trying to reassign the variable constant.

// to enable this work, we can say;
let age = 33;
age = age + 1;

console.log(age); //34
//this will be a way to fix error.




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


//ReferenceError: Cannot access 'cityOfBirth' before initialization
// you always need to declare a variable before using it.
11 changes: 10 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);


console.log(last4Digits); // "4213"

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


/* I don't think it will work, because card number is a number,
and .slice() is a string method and we must convert the number to string method to work*/

//TypeError: cardNumber.slice is not a function. this was after running node.
13 changes: 11 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const Hour12ClockTime = "20:53";
const hour24ClockTime = "08:53";

console.log(Hour12ClockTime); //"20;53"
console.log(hour24ClockTime); // "08:53"

// SyntaxError: Invalid or unexpected token.
// variable names cannot start with number.

// renaming our variable would be the right thing.

11 changes: 11 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ 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?


// a) 5 function calls. 2 in line 4, 2 in line 5, and 1 in line 10.

// b) SyntaxError: missing ) after argument list. There is a missing comma after argument. It can be fixed by adding a comma.

// c) line 4 and 5.

// d) line 1,2, 7, and 8.

// e) The expression is used to remove commas from the string and convert it into a number so it can be used in calculations.
19 changes: 18 additions & 1 deletion 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 = -8784; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -23,3 +23,20 @@ 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



// a) 6 variables declarations.

// b) 1 function call.

/* c) The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
In this case it will give the remainder of 8748 % 60 */

// d) It simply wants to get the length of the movie in minutes. subtract the remaining seconds from the movie length and convert to minutes.

// e) It represents the movie durations in hours, minutes and seconds. (movie duration).

/*f) I have tried three values and it worked. It will work perfectly for larger and smaller numbers.
However, with negative values it gives negative figures.*/

10 changes: 10 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,13 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"

// 2.line 3-6 function is trying to remove the p and make the strings numeric only.

// 3.line 8 ensure there are three characters and can split equally to pounds and pence.

// 4.line 9-12 this is extracting pounds from the number.

// 5.line 14-16 ensure the pence always have 2 digits.

// line 18 gives the value in pounds and pence.
6 changes: 6 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ Now try invoking the function `prompt` with a string input of `"What is your nam

What effect does calling the `prompt` function have?
What is the return value of `prompt`?


line 13- when i ran the function on console tab, it showed a new word hello world in the next line.

line 17&18 - when i ran the 'prompt' function it pop up a box for imputing my name and it returned undefined.
after i wrote myname in the next line it brought out my name.
14 changes: 14 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

line 7 =ƒ log() { [native code] }

line 9 = console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

line 11 = 'object'


line 15 =console is like an object that helps to store methods used for debugging and printing output in the browser’s developer tools.


line 16 = 'console.log'means access or get the log function fom the object console.
'console.assert' means access or get the assert function from the object console.
while the '.' is an access operator that access methods or properties from and object.
Loading