Skip to content
12 changes: 12 additions & 0 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Predict and explain first...
// =============> write your prediction here

//str has allready been declared.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

Expand All @@ -10,4 +12,14 @@ function capitalise(str) {
}

// =============> write your explanation here
/*
I think its because of been called multiple times, at "let str" after "funtion capitalise(str)"
changing "let str" to "let capitalised" should help the issue.
*/
// =============> write your new code here
/*
function capitalise(str) {
let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalised;
}
*/
21 changes: 19 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

// Why will an error occur when this program runs?
// =============> write your prediction here

/*
Yes an error will occur.
decimalNumber has been declared
an error will another errour would be for, decimalNumber is not defined
*/
// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
Expand All @@ -15,6 +19,19 @@ function convertToPercentage(decimalNumber) {
console.log(decimalNumber);

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

/*
decimalNumber has been called and set as a const.
"console.log(decimalNumber)" wont work as decimalNumber only excistes inside the function not outside it.
*/
// Finally, correct the code to fix the problem
// =============> write your new code here
/*
function convertToPercentage(decimalNumber) {
const decimal = 0.5;
const percentage = `${decimal * 100}%`;

return percentage;

}
console.log(convertToPercentage)
*/
13 changes: 9 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

// 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
Expand All @@ -10,11 +9,17 @@ function square(3) {
}

// =============> write the error message here
// SyntaxError: Unexpected number

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

// the (3) is a value not a variable or parimitor name, it should be num instead for the functino to work corretly.
// Finally, correct the code to fix the problem

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


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

console.log (square(3));
*?
14 changes: 13 additions & 1 deletion Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Predict and explain first...

// =============> write your prediction here
// is going to have undefined

function multiply(a, b) {
console.log(a * b);
Expand All @@ -9,6 +10,17 @@ function multiply(a, b) {
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

/*
its going to have undefined for the ${multiply(10, 32) as in teh function it has console.log.
It needs to have "return" in order for it to keep teh vaule for the function as it is only displying it right now.
*?
// 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)}`);

*/
9 changes: 9 additions & 0 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
// return undefined for ${sum(10, 32)}

function sum(a, b) {
return;
Expand All @@ -9,5 +10,13 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// in the function return is split from a + b by ;
// 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)}`);
*/
18 changes: 18 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Predict the output of the following code:
// =============> Write your prediction here
// There wont be an error warning shown, it will show 3 request.

const num = 103;

Expand All @@ -15,10 +16,27 @@ 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
/*
The last digit of 42 is 3
The last digit of 105 is 3
The last digit of 806 is 3
*/
// Explain why the output is the way it is
// =============> write your explanation here
/* Simply the "const num = 103" is forcing return num to be 103 at all times.
This can be fixed by putting num in getLastDigit(num), removing the "const num = 103" as it isnt needed.
// 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
7 changes: 6 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,10 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
let squaredHeight = (height * height);
let baseBmi = (weight / squaredHeight);
return bmi = Math.round(baseBmi * 10) / 10;
}
console.log (`BMI is ${calculateBMI(70,1.73)}`);

// return the BMI of someone based off their weight and height
}
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 UpperSnake(text) {
let upperCase = text.toUpperCase();
let snakeCase = upperCase.replaceAll(" ","_");
return snakeCase;
}

console.log(UpperSnake("hello there bob"));
5 changes: 5 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,8 @@
// 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
function toPounds(weight) {
return (weight * 2.204);
}

console.log(toPounds(70))
10 changes: 5 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) {
// Questions

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

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

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> "61"

// 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
// =============> 1, when pad is last called its at ${pad(remainingSeconds)} where the value left is 1

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> 1 at const remainingSexonds = seconds % 60 gives 1
Loading