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
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 of the code assigns a value to the declared variable count.
// The = sign is an assignment operator, without line 3, the declared variable wil be undefined.
3 changes: 1 addition & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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[0]}+${middleName}+${lastName}`;

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

4 changes: 2 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,7 @@ 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,filePath.length-base.length-1) ;
const ext = filePath.slice(-3);

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

// In the above expression num represent a variable that will store the result of that will be obtained from from the expression.
// maximum and minimum are variables available on the global scope, as inputs.
// They are evaluated first because of the parenthesis, this gives the precedence
// The output from the parenthesis is now going to serve as the range for the Math.random() method.
// Math.random() method produce random values from 0-1, with 0 and 1 inclusive and exclusive respectively
// The range value makes Math.random() to return result from 0 to range-1
//the Math.floor() methods rounds down the value to the nearest whole number.
// The result from th random operation is added back to the minimum value to return num.
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;
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

// JavaScript is single-threaded because it executes tasks in a single flow using a call stack. The function was called before it was declared,
// It was also declared with const, which can not be hoisted to the top, like var.
// this result to undefined.

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const cardNumber = 4533787178994213;
let cardNumber = 4533787178994213;
cardNumber=cardNumber.toString();
const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
Expand All @@ -7,3 +8,7 @@ const last4Digits = cardNumber.slice(-4);
// 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

// The variable cardNumber is a number data type, numbers do not have slice methods or function, only string does.
//TypeError: cardNumber.slice is not a function
// Yes, it gives what i predicted
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";
13 changes: 12 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,21 @@ 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

//There are 5 function call in this code.
// 1. Line 4 has 2 function call, .replaceAll() and Number()
//2. Line 5 ditto line 4
// 3. line 10 console.log() that logs the result to the console

// 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 in this code is coming from line 5. The wrong use of the replaceAll syntax without a separator.
// I will fix this problem by reading the documentation, to see the right way the syntax should be written.
//Then i will add the comma where necessary

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

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// this expression replaces the comma at the string with an empty string and the convert the string data type to a number data type
11 changes: 11 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,25 @@ 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 variable declaration.


// b) How many function calls are there?
// One function call

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// The % operator checks the remainder of that expression when being evaluated. It is similar to the remainder theorem in mathematics.
// if it returns 0, even, if it returns value other than zero, it odd. it is mostly used for checks in programming

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The total time for this movie is 8760 second and fractional 24 seconds, line 4 is used to deduct the fractional 24 seconds
// Then convert the whole number seconds to minute.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// the variable result represent total movie duration in hours,minute and seconds.
// const=movieLength

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// this code works for all movie length and integer values.
// for movie length which are multiples of 60 it returns hours with 0 minutes and 0 seconds
18 changes: 11 additions & 7 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ const penceStringWithoutTrailingP = penceString.substring(
);

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

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

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

Expand All @@ -25,3 +20,12 @@ 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);: used to strip off the last substring character 'p'
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): Used to add '0' to the start of the string if the string
// length is less than 3, else if string length is 3 it does not pad.
// 4.const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);: This expression copy the first character
// from every length character of the padded string
// 5.const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2).padEnd(2, "0");: This expression add '0' to the end if the paddedString is not
// upto 2 characters
// 6. this line is a function call to log the argument inside it to the console. it use template literals to get the values of the variables

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 @@ -10,9 +10,16 @@ Let's try an example.
In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

It invokes the modal window and display Hello world

What effect does calling the `alert` function have?
It freezes the window till i click Ok before ii can make use of my computer

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`.
const myName=prompt(`"What is your name?"`)
return value myName=Edak

What effect does calling the `prompt` function have?
it invokes a modal window, and allows me to enter an input value
What is the return value of `prompt`?
it returns the value i entered "Edak"
11 changes: 10 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,21 @@ 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?
I get `f log(){[native code]}` in return

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

Try also entering `typeof console`

I get `object`
Answer the following questions:

What does `console` store?
The console store methods for debugging the console such as assert. clear,count,countReset,debug etc

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

console.log: Output a message to the console

console.assert: Log an error message to the console if the first argument is false.
`.` console is the class the . helps you to access the methods or properties of the class console.
Loading