Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let count = 0;

count = count + 1;
console.log(count)

// 1 - From running slightly =0, then add extra line with +1. With new count =0+1=1, is assing

// 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 - the line 3 provide new value for count
8 changes: 7 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,13 @@ 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 = ``;
function initials(character) {
return character.toString().slice(0,1);
}

console.log(`The first character of each string is ${initials(firstName)}${initials(middleName)}${initials(lastName)}`);



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

7 changes: 5 additions & 2 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?
console.log(`Random number between ${minimum} and ${maximum}: ${num}`);


// In this exercise, you will need to work out what num represents? - generates a random integer between minimum and maximum by formula
// 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
// Try logging the value of num and running the program several times to build an idea of what the program is doing - Each time run the program, num will be different, and it will always be between 1 and 100, inclusive.
5 changes: 3 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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?
// We need to add - //
14 changes: 13 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
const age = 33; //we need to change const to let.
age = age + 1;

let age2 = 33;
age2 = age2 + 1;
console.log (age2);

//or we can use const age but add another variable

const age3 = 33;
let age4 = age3 + 1;
console.log (age4);


5 changes: 5 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,8 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// need to change lines, console.log need be in the end

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
20 changes: 16 additions & 4 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);

// 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?
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work - we don't have consele.log
// Then run the code and see what error it gives. - TypeError: cardNumber.slice is not a function
// Consider: Why does it give this error? Is this what I predicted? If not, what's different? - so we don't have a function, we don't return any answer
// Then try updating the expression last4Digits is assigned to, in order to get the correct value

const cardNumber = 4533787178994213;

function lastDigits(cardNumber) {
const cardStr = cardNumber.toString(); // Convert the number to a string
return cardStr.slice(-4); // Get the last 4 digits
}

console.log(`The last 4 digits are ${lastDigits(cardNumber)}`);



2 changes: 1 addition & 1 deletion 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 24hourClockTime = "08:53"; //I don't understand the task
10 changes: 6 additions & 4 deletions 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(",","")); // I see syntax problem, it's missing coma ,

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -12,11 +12,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
// I see just one function call - console.log (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?

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

//line 4 and 5
// d) Identify all the lines that are variable declarations

// all the lines with let and const 1, 2, 7, 8
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// carPrice.replaceAll(",", "") removes all commas from the string, producing "10000" and "8543".
11 changes: 6 additions & 5 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,15 @@ 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?

// 6 in total all line with const
// b) How many function calls are there?

// just one line 10 - console.log
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

//Since movieLength is in seconds, movieLength % 60 gives the remaining seconds after dividing the total time into full minutes.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

//The expression (movieLength - remainingSeconds) / 60 converts the total movie length in seconds to the total number of full minutes.
// e) What do you think the variable result represents? Can you think of a better name for this variable?

//The variable result represents the formatted movie length in the format. Name can be movieTimeFormatted
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// yes it's will work
6 changes: 6 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,9 @@ 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); : removing p from the number 399
// 3. const paddedPenceNumberString : we are checking if the number has min 3 digits, if less than we will add "0" in the start.
// 4. paddedPenceNumberString.length - 2 : calculates the position 2 characters from the end.
// 5..substring(paddedPenceNumberString.length - 2 : extracts the last 2 characters.
// 6. .padEnd(2, "0") : if our new number (paddedPenceNumberString.length) will have less then 2 digits we will add extra 0.
// 7. console.log(`£${pounds}.${pence}`) : the result where we will add pounds and pence together.
12 changes: 10 additions & 2 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here - we don't have console.log, it's will not show anyting


// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
Expand All @@ -9,5 +10,12 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> write your explanation here - SyntaxError: Identifier 'str' has already been declared
// We need to change let to another name so it's not much with variables
// =============> write your new code here

function capitalise(str) {
let capitalizedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalizedStr;
}
console.log(capitalise("hello"));
11 changes: 9 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> write your prediction here - we are return percentage but in console.log decimalNumber, we need to change decimalNubmer to real number

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

Expand All @@ -14,7 +14,14 @@ function convertToPercentage(decimalNumber) {

console.log(decimalNumber);

// =============> write your explanation here
// =============> write your explanation here - SyntaxError: Identifier 'decimalNumber' has already been declared

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

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

console.log(convertToPercentage(0.5));
12 changes: 9 additions & 3 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

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

// =============> write your prediction of the error here
// =============> write your prediction of the error here - Undefine error.As we don't have parameter num.

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

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

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

// =============> write the error message here - Syntax Error.

// =============> explain this error message here - mistake in the function name, as parameter can't start with the number.

// Finally, correct the code to fix the problem

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

function square(num) {
return num * num;
}
console.log(square(3))

11 changes: 9 additions & 2 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Predict and explain first...

// =============> write your prediction here
// =============> write your prediction here - undefined as we don't have parameters a and 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
// =============> write your explanation here - The result of multiplying 10 and 32 is undefined

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

function multiplyFixed(a, b) {

return (a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiplyFixed(10, 32)}`);
16 changes: 12 additions & 4 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here - undefined as we don't have parameter return

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

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

// =============> write your explanation here - undefined as we don't have parameter return

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

function sum(a, b) {
return (a + b);

}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
22 changes: 16 additions & 6 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...
// Predict and explain first - 4,2 , 10,5 , 80,6

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here - if slice -1 from the number, then 42 slice will be 4,2

const num = 103;

Expand All @@ -13,12 +13,22 @@ 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)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
// Explain why the output is the way it is
// =============> write your explanation here
// Now run the code and compare the output to your prediction
// - 3 - slice (-1) takes from const number and not from getLastDigit
// Explain why the output is the way it is - in the code don't getLastDigit parameter
// in the code don't getLastDigit parameter
// Finally, correct the code to fix the problem
// =============> write your new code here

const num = 103;

function getLastDigit(num2) {
return num2.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
10 changes: 9 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
let squaringHeight = height * height;
let BMI = weight / squaringHeight;

return BMItoFixed(1);

// return the BMI of someone based off their weight and height
}
}

console.log (calculateBMI(50,1.65));

11 changes: 11 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,14 @@
// 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

function caseSnake(sentence) {
return sentence.toUpperCase().replace(/ /g, "_");
}

console.log(caseSnake("hello there"));





22 changes: 16 additions & 6 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// 3 times - totalHours, remainingMinutes, remainingSeconds

// Call formatTimeDisplay with an input of 61, now answer the following:

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// When formatTimeDisplay(61) is called:
//seconds = 61
//remainingSeconds = 61 % 60 = 1
//totalMinutes = (61 - 1) / 60 = 1
//remainingMinutes = 1 % 60 = 1
//totalHours = (1 - 1) / 60 = 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
//When pad(0) is called:

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
//num.toString() converts 0 to "0".
//.padStart(2, "0") ensures the string is at least 2 characters long by padding it with "0" at the start.

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
//The last time pad is called is for remainingSeconds, which is the value of 1 in this case (from remainingSeconds = 61 % 60 = 1
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// When pad(1) is called:

//num.toString() converts 1 to "1".
//.padStart(2, "0") ensures the string is at least 2 characters long by padding it with "0" at the start.
Loading