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
11 changes: 5 additions & 6 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Predict and explain first...
// =============> write your prediction here
// =============> When we call capitalise("fay"), it will throw an error instead of returning "Fay"

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

// =============> "str" has already been declared, in JavaScript we can not redeclare a parameter using let inside the same scope.
// =============> write your new code here
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
return str = `${str[0].toUpperCase()}${str.slice(1)}`;
}

// =============> write your explanation here
// =============> write your new code here
console.log(capitalise("fay"));
17 changes: 10 additions & 7 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> 'decimalNumber' has already been declared.


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

// =============>The variable in line 9 "decimalNumber" is declared as a parameter passed to the function
// but in line 10 the variable redeclared again.
// Finally, correct the code to fix the problem
// =============> write your new code here

const decimalNumber = 0.5;

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;

const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);

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

// Finally, correct the code to fix the problem
// =============> write your new code here
13 changes: 7 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

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

// =============> write your prediction of the error here
// =============> Function parameters must be variable names not values.

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

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

// =============> explain this error message here
// =============> We can not put a number (3) as a parameter name.

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}
console.log(square(3));


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

// =============> write your prediction here
// =============> The result of the multiplying is undefined

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
// =============> The function logs the result but does not return anything.

// 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)}`);
12 changes: 5 additions & 7 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Predict and explain first...
// =============> write your prediction here
// =============> The sum of 10 and 32 is undefined

// =============> The line break and the semicolon after "return" stops the function and returns undefined.
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return;
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
18 changes: 9 additions & 9 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> The last digit will be 3 with all the function.

// Now run the code and compare the output to your prediction
// =============> write the output here
// Explain why the output is the way it is
// =============> A function "getLastDigit" must declare parameters to receive arguments.
//If it doesn’t, any arguments passed in are ignored.
// Finally, correct the code to fix the problem
// =============> write your new code here
const num = 103;

function getLastDigit() {
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)}`);

// 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
// Finally, correct the code to fix the problem
// =============> write your new code here

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
5 changes: 4 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,7 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const bmi = weight / height ** 2;
return parseFloat(bmi.toFixed(1));
}
console.log(calculateBMI(60, 1.70));
5 changes: 5 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,8 @@
// 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 toUpperSnakeCase(str) {
return str.toUpperCase().replaceAll(" ", "_");
}
console.log(toUpperSnakeCase("hello there"));
console.log(toUpperSnakeCase("lord of the rings"));
19 changes: 19 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,22 @@
// 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(penceString) {
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");

return ${pounds}.${pence}`;
}
13 changes: 6 additions & 7 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ function formatTimeDisplay(seconds) {
// to help you answer these questions

// Questions

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

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

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

// 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=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
// =============> "01"
9 changes: 2 additions & 7 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ function formatAs12HourClock(time) {
return `${time} am`;
}


const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
`Expected ${targetOutput} but got ${currentOutput}`
);

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);