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
13 changes: 8 additions & 5 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Predict and explain first...
// =============> write your prediction here

// call the function capitalise with a string input
// =============> We use a string template when we want to join different character sets together but by casing the first letter
// to uppercase we're assuming that it is formed of letters
// interpret the error message and figure out why an error is occurring

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

// =============> write your explanation here
// =============> write your new code here
// Te error message says 'str' has already been declared so we can use another name for our
//output to solve that error we change the output variable name
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
//}
18 changes: 13 additions & 5 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
// The parameter is a constant which means the program will output the same thing everytime,
//and would give an error message saying it has been declared if run.

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

Expand All @@ -10,11 +11,18 @@ function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;

return percentage;

console.log(decimalNumber);
}
// =============> Our parameter has already been declared which is why the program is resulting in an error

console.log(decimalNumber);
// Finally, correct the code to fix the problem
// function convertToPercentage(decimalNumber) {
// const decimalNumber1 = 0.5;
//const percentage = `${decimalNumber1 * 100}%`;

// =============> write your explanation here
// return percentage;
// console.log(decimalNumber1);
//}

// Finally, correct the code to fix the problem
// =============> write your new code here
//
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

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

//We are going to get an error because an integer cannot be a parameter, it has to be a variable.
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
//syntaxERror, identifier cannot be an integer

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

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

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

//The program was expecting a function parameter but got a number instead
// Finally, correct the code to fix the problem

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


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

// =============> write your prediction here

//This won't work because we are not returning anything.

function multiply(a, b) {
console.log(a * b);
}
Expand All @@ -11,4 +12,9 @@ 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
//function multiply(a, b) {
//return a * b;
//}

//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
// =============> write your new code here
7 changes: 7 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
//This won't work because of a syntax error, return a+b should be on a single line and not on separate lines

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

// =============> write your explanation here
// The sum of a + b is undefined because we are not returning any value
// 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: 14 additions & 4 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
// =============> Write your prediction
//It should output string cannot be accessed because we are using normal brackets instead of square brackets

const num = 103;

Expand All @@ -14,11 +15,20 @@ 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
// =============>The output was 3 for all instead of the last digit of each number.
//
// Explain why the output is the way it is
// =============> write your explanation here
// =============> This is because we already declared the num variable as a constant
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> 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
//There was no parameter so the function wasn't running properly.
//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)}`);
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 @@ -14,6 +14,10 @@
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
function calculateBMI(weight,height) {
return (weight/(height*height)).toFixed(1);

// return the BMI of someone based off their weight and height
}
}
console.log(`Your BMI is ${calculateBMI(56,1.5)}`)
//console.log(`Your BMI is ${calculateBMI(weight,height)}`)
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 caseToUpperS(string){
return string.toUpperCase().replaceAll(" ", "_");

}
console.log(`Your new word is ${caseToUpperS("i love cyf so much")}`)
33 changes: 33 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,36 @@
// 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){

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

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

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

return {pounds, pence};
}
const { pounds, pence } = toPounds("10390p");

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



// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds

// You need to do a step-by-step breakdown of each line in this program
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
Loading