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

// = is assigning the value of 'count',
// 'let' is a declararation than enables its subject (count) to be changed
// line 3 is taking the current value in line 1 (0) and by using '=' it is reassigning the value of 'count' to equal itself plus 1
10 changes: 7 additions & 3 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
// =============> The fuction intends to capitalize the first letter of the input string
// from th left starting with the first character (str[0]).

// 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,8 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> write your new code here
// =============> str has already been declared as a parameter function, so it cannot be redeclared within the function body. This will cause a syntax error. To fix this, we should use a different variable name for the new string we are creating.
// =============>
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
14 changes: 10 additions & 4 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// Why will an error occur when this program runs?
// =============> decimalNumber is a constant variable, and cannot be changed.
// The code is attempting to change it which will cause an error.

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

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

console.log(decimalNumber);

// =============> write your explanation here
// =============> The code is attempting to get the percentage of decimalNumber

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log (convertToPercentage(0.5));
12 changes: 8 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

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

// =============> write your prediction of the error here
// =============> num is not defined which causes an error.

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

// =============> write the error message here
// =============> 1. "Uncaught SyntaxError: Unexpected number" Means the "3" is not valid there.
// 2. Uncaught SyntaxError: Illegal return statement. Means "num" has no idea of what it should be

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

// Finally, correct the code to fix the problem

// =============> write your new code here
// =============> by adding square(num) the function will work when given a number
function square(num) {
return num * num;
}
console.log(square(3))


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

// =============> write your prediction here
// =============> Code is attempting to multiple a & b but there is no return value

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
// =============> because there is no return value, the outcome stays as undefined while giving the answer
// to fix this, change "console.log" in the second row to "return"
//

// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return (a * b);
}
13 changes: 10 additions & 3 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Predict and explain first...
// =============> write your prediction here
// =============> the function is attempting to add "a" & "b" together
// but the return is formatted wrong.

function sum(a, b) {
return;
Expand All @@ -8,6 +9,12 @@ function sum(a, b) {

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

// =============> write your explanation here
// =============> because of the way line 6 and 7 is written the answer will be undefined.
//remove the semi colon from line 6 and then add line 7 to it.
// Finally, correct the code to fix the problem
// =============> write your new code here

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

console.log(sum(10, 32))
22 changes: 17 additions & 5 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> The function is trying to get the last digit of "num"
// but because on "const", the "num" is always locked to "103" leaving the return always "3"

const num = 103;

Expand All @@ -14,11 +15,22 @@ 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
// =============> Just as predicted, the function is trying to get the last digit, which is always "3"
// Explain why the output is the way it is
// =============> write your explanation here
// =============> because of "const" the num is always locked to "103"
// 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
// Explain why getLastDigit is not working properly
// It's not working properly because of the "const num = 103"
// to fix, I have removed the line and added "(num)" after "function getLastDigit"
// In order to define what "num" is.
9 changes: 8 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@

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

function calculateBMI(weight, height) {
const bmi = weight / (height * height);
return parseFloat(bmi.toFixed(1));
}

console.log(calculateBMI(70, 1.73));
8 changes: 8 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,11 @@
// 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 Capitalise(inputString) {
return inputString.toUpperCase()

}

Console.log(Capitalise("hello there"));
20 changes: 20 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,23 @@
// 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

const penceString = "399p";

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

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

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

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

Loading