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: 1 addition & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ let count = 0;
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
// Describe what line 3 is doing, in particular focus on what = is doing --> = means a assignment on itself +1
3 changes: 3 additions & 0 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ let lastName = "Johnson";

let initials = ``;

initials = `${firstName[0]}, ${middleName[0]}, ${lastName[0]}`;

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

//console.log(initials);
17 changes: 14 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ 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.lastIndexOf("/"));
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);

// https://www.google.com/search?q=slice+mdn
console.log(dir);
console.log(ext);

/*
Explanation:

filePath.lastIndexOf(".") finds the position of the last dot in the path.

slice() extracts the substring starting one position after the dot (hence +1), giving just the extension without the dot.
*/

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

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
// In this exercise, you will need to work out what num represents? --> num gives a random number between 1 and 100
// Try breaking down the expression and using documentation to explain what it means --> Math.floor() give the rounded number below
// --> Math.random give a number between 0 and 1 but never 1
// It will help to think about the order in which expressions are evaluated --> first what is in parenthesis
// 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);
2 changes: 1 addition & 1 deletion 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?
We don't want the computer to run these 2 lines - how can we solve this problem? --> with /* */
1 change: 1 addition & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

const age = 33;
age = age + 1;
// --> let age =33; instead of using const
1 change: 1 addition & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
//--> cityOfBirth must be declared before the console.log of cityOfBirth
2 changes: 2 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ 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
console.log(last4Digits);
//--> .slice() works only with a string --> add '4533'
4 changes: 3 additions & 1 deletion 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 24hourClockTime = "08:53";

//--> we mustn't begin a name's variable with integer
13 changes: 7 additions & 6 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let carPrice = "10,000";
let priceAfterOneYear = "8,543";
let carPrice = 10000;
let priceAfterOneYear = 8543;

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
Expand All @@ -11,12 +11,13 @@ console.log(`The percentage change is ${percentageChange}`);

// 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 --> Number() line4 and line5

// 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? --> the 2 variables are strings and Number returns a integer

// c) Identify all the lines that are variable reassignment statements
// c) Identify all the lines that are variable reassignment statements -->4,5,7,8

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// --> Number gives the integer or real number and .replace() works with a string and replace all "," by nothing ""
13 changes: 7 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,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 65; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -11,15 +11,16 @@ 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 because in the same time, there are assignments

// b) How many function calls are there?
// b) How many function calls are there? --> 0 because console.log() is a method

// c) Using documentation, explain what the expression movieLength % 60 represents
// c) Using documentation, explain what the expression movieLength % 60 represents --> % is the modulo which gives the remaining
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? -->We remove the seconds and divide with 60 to have the remaining time without the seconds

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

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//--> not with a negative number
11 changes: 8 additions & 3 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
penceString.length - 1 // take only 399
);
console.log(penceStringWithoutTrailingP);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //The padStart() adds characters to the beginning of a string until the string reaches a specified total length
console.log(paddedPenceNumberString);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
paddedPenceNumberString.length - 2 // gives only the pound
);
console.log(pounds);

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

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

// This program takes a string representing a price in pence
Expand Down
6 changes: 3 additions & 3 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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?
What effect does calling the `alert` function have? --> a small windows with the words 'Hello world!' appears

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? --> a input small window appears and we have to enter something
What is the return value of `prompt`? --> undefined
1 change: 1 addition & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
//--> console is a object. The . call the property or a method
9 changes: 6 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// =============> write your prediction here

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
// interpret the error message and figure out why an error is occurring --> str is already declared when the function is declared

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
let str2 = `${str[0].toUpperCase()}${str.slice(1)}`;
return str2;
}

// =============> write your explanation here
// =============> write your new code here

let test = "tamTamyngo";
console.log(capitalise(test));
8 changes: 4 additions & 4 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> write your prediction here --> decimalNumber is a variable which is declarer already

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
// const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
const test = 0.25;
console.log(convertToPercentage(test));

// =============> write your explanation here

Expand Down
11 changes: 7 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@

// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here

function square(3) {
/* function square(3) {
return num * num;
}
} */

// =============> write the error message here

// =============> explain this error message here

// Finally, correct the code to fix the problem
// Finally, correct the code to fix the problem --> need a parameter num

// =============> write your new code here

function square(num) {
return num * num;
}

console.log(square(3));
14 changes: 10 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Predict and explain first...
// Predict and explain first... --> the function must give the multiplication of 2 numbers as argument

// =============> write your prediction here
// =============> write your prediction here don't use a return but a console.log which is not reusable later

function multiply(a, b) {
/* function multiply(a, b) {
console.log(a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

*/
// =============> write your explanation here

// Finally, correct the code to fix the problem
// =============> write your new code here

function multiply(a, b) {
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10 changes: 7 additions & 3 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Predict and explain first...
// Predict and explain first... --> sum() must return a sum of a and b but error because of ; after return
// =============> write your prediction here

function sum(a, b) {
/* function sum(a, b) {
return;
a + b;
}
} */

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here

function sum(a, b) {
return a + b;
}
18 changes: 12 additions & 6 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here --> a integer is transformed to a string and .slice() take only the last character

const num = 103;
/* const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
}
} */

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
/* console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`); */

// Now run the code and compare the output to your prediction
// =============> write the output here
// Explain why the output is the way it is
// Explain why the output is the way it is --> because we use num
// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here
function getLastDigit(num) {
return num.toString().slice(-1);
}
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
8 changes: 6 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
// return the BMI of someone based off their weight and height
let BMI = weight / (height * height);

Choose a reason for hiding this comment

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

well done on that method

return Math.round(BMI * 10) / 10; // Return rounded BMI with one decimal place as a number (not string)
}

console.log(calculateBMI(70, 1.73));
6 changes: 6 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

let toUp = function (str) {
let newStr = str.toUpperCase().replace(/ /g, "_");
return newStr;
};
console.log(toUp("lord of the rings"));
22 changes: 22 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,25 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

let toPounds = function (str) {
const penceStringWithoutTrailingP = str.substring(
0,
penceString.length - 1 // take only 399

Choose a reason for hiding this comment

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

penceString variable is a variable defined outside, Maybe you meant str? Check this please

);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //The padStart() adds characters to the beginning of a string until the string reaches a specified total length

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2 // gives only the pound
);

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
return ${pounds}.${pence}`;
};

const penceString = "399p";
console.log(toPounds(penceString));
Loading