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

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

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

module.exports =capitalise ;


// =============> write your explanation here
// =============> write your new code here
15 changes: 3 additions & 12 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
// Predict and explain first...

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

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

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

return percentage;
}

console.log(decimalNumber);

// =============> write your explanation here
module.exports = convertToPercentage;
//console.log(convertToPercentage(0.5));

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

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

function square(3) {
function square(num) {
return num * num;
}
module.exports = square;
//console.log(square(3));

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

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

// Finally, correct the code to fix the problem

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


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

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

function multiply(a, b) {
console.log(a * b);
return(a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
module.exports = multiply;
//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
// =============> write your new code here
12 changes: 3 additions & 9 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Predict and explain first...
// =============> write your prediction here

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

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
module.exports = sum;
//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
26 changes: 6 additions & 20 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here

const num = 103;

function getLastDigit() {
let num;
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
module.exports = getLastDigit;
//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
6 changes: 5 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,8 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const bmi = weight / (height*height);
return bmi.toFixed(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toFixed returns a string, so be careful

}

console.log(calculateBMI(70,1.70));
4 changes: 4 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,7 @@
// 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 upperAndSnakeCase(string){
return string.replaceAll(' ', '_').toUpperCase();
}
console.log(upperAndSnakeCase("lord of the rings"));
16 changes: 16 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,19 @@
// 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 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");
return `£${pounds}.${pence}`;
}

console.log(toPounds("11150p"));
11 changes: 6 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ function formatTimeDisplay(seconds) {

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

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

00:01:01
// 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

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
2 changes: 2 additions & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
}else if (hours === 12){
return `${hours}:00 pm`;
}
return `${time} am`;
}
Expand Down
47 changes: 47 additions & 0 deletions Sprint-2/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const capitalise = require('./1-key-errors/0');
const convertToPercentage = require('./1-key-errors/1');
const square = require('./1-key-errors/2');
const multiply = require('./2-mandatory-debug/0');
const sum = require('./2-mandatory-debug/1');
const getLastDigit = require('./2-mandatory-debug/2');

describe('capitalise', () => {
test('capitalises first letter', () => {
expect(capitalise('ok')).toBe('Ok');
});
});

describe(`convertToPercentage`, () => {
test(`convert to percentage`, () =>{
expect(convertToPercentage(`0.5`)).toBe(`50%`);
})

})

describe(`square`, () => {
test(`square of 3 should be 9`, () =>{
expect(square(3)).toBe(9);
})
})


describe('multiply', () => {
test('the product of two numbers', () => {
expect(multiply(10,32)).toBe(320);
});
});

describe(`sum`, ()=> {
test(`The sum of 10 and 32`, () => {
expect(sum(10,32)).toBe(42);
});
});

describe(`Last digit`, () =>{
test(`get last digit`, () =>{
expect(getLastDigit(`42`)).toBe(`2`);
});
});

// tests of practice-tdd

Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
return 5;
}

module.exports = countChar;
28 changes: 28 additions & 0 deletions Sprint-3/2-practice-tdd/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const countChar = require('./count');
const getOrdinalNumber= require('./get-ordinal-number');
const repeat = require('./repeat');

describe('countchar', () => {
test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(5);
});
});


describe(`ordinalNumber`, () =>{
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});
});

describe('repeat', () => {
test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});
});
Empty file added Sprint-3/3-stretch/test.js
Empty file.
Loading