Skip to content

West Midlands | Gabriel Deng | Module-Structuring-and-Testing-Data | Sprint-2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion Sprint-1/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

console.log(`I was born in ${cityOfBirth}`);

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);


//This is a hosting error. You can't use a variable before declaring it. I have made some changes on how I believe it should be.
10 changes: 9 additions & 1 deletion Sprint-1/errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const cardNumberStrings = cardNumber.toString();
const last4Digits = cardNumberStrings.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// Then try updating the expression last4Digits is assigned to, in order to get the correct value


// I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer.

//I used toString method on the cardNumber to turn it into strings and then use slice to retrieve the last 4 digits.

// I converted the cardNumber integers into a string and assigned them to a variable called cardNumberStrings, this way, I can continue using the 'const' declaration instead of using the 'let'
8 changes: 6 additions & 2 deletions Sprint-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const twenty4HourClockTime = "20:53";
const twelveHourClockTime = "08:53";

// This is a wrong declaration syntax, variables can't start with numbers, special characters or contain reserved words.

//I neglect that fact the two variables have the same names since Javascript variable names are not
2 changes: 2 additions & 0 deletions Sprint-1/exercises/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ 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

//Line 3 is about an assignment operator used to increase the count variable by 1.
4 changes: 4 additions & 0 deletions Sprint-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const num = 56.5678;

const wholeNumberPart = Math.floor(num);
const decimalPart = (num % 1).toFixed(4);
const roundedNum = Math.round(num);

// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num )
Expand Down
2 changes: 2 additions & 0 deletions Sprint-1/exercises/initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";

const initials = firstName[0] + middleName[0] + lastName[0]

// Declare a variable called initials that stores the first character of each string.
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
4 changes: 4 additions & 0 deletions Sprint-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable


const dir = filePath.slice(0, lastSlashIndex);
const ext = base.slice(base.lastIndexOf(".") + 1);
5 changes: 4 additions & 1 deletion Sprint-2/debug/0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Predict and explain first...

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

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

// The function returns undefined but it will log the product of the inputs to the console tab.
5 changes: 3 additions & 2 deletions Sprint-2/debug/1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Predict and explain first...

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

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

//The function returns undefined since the value has not been assigned to it.
4 changes: 3 additions & 1 deletion Sprint-2/debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
return num.toString().slice(num.length - 1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
Expand All @@ -12,3 +12,5 @@ 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

//Using slice(-1) is not a feasible method to use in this case. The correct way to do the code is by using num.toString().slice(num.length - 1)
5 changes: 5 additions & 0 deletions Sprint-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}


capitalise('hello world')

// This function is intended to get the first character in a string entered.
7 changes: 5 additions & 2 deletions Sprint-2/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
// 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);
console.log(convertToPercentage(0.5));


// The function won't work because variable name declared cannot be used since it is used as a parameter.
3 changes: 2 additions & 1 deletion Sprint-2/errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

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

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


// This function will return a syntax error because a number is used instead of a parameter. The correct function declaration should have a parameter instead of a value.
21 changes: 21 additions & 0 deletions Sprint-2/extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

const currentOutput3 = formatAs12HourClock("16:00");
const targetOutput3 = "4:00 pm";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
)

const currentOutput4 = formatAs12HourClock("19:00");
const targetOutput4 = "7:00 pm";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
)

const currentOutput5 = formatAs12HourClock("20:00");
const targetOutput5 = "8:00 pm";
console.assert(
currentOutput5 === targetOutput5,
`current output: ${currentOutput5}, target output: ${targetOutput5}`
)
6 changes: 6 additions & 0 deletions Sprint-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
// Given someone's weight in kg and height in metres
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place

const findBMI = (weight, height) => {
return (weight / (height ** 2)).toFixed(1);
}

findBMI(70, 1.73);
10 changes: 10 additions & 0 deletions Sprint-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@

// You will need to come up with an appropriate name for the function
// Use the string documentation to help you find a solution

const upperSnakeCase = (input) => {
for ( let i = 0; i < input.length; i++) {

}
const upperCase = input.replace(/\s+/g, '_').toUpperCase();
console.log(upperCase)
}

upperSnakeCase('lords of the rings');
18 changes: 18 additions & 0 deletions Sprint-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@
// 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 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");

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

toPounds('3455p');
6 changes: 6 additions & 0 deletions Sprint-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
// Given a number,
// When I call this function with a number
// it returns the new price with VAT added on

const calcualteVat = (price) => {
return `£${price * 1.2}`;
}

calcualteVat(60);
5 changes: 5 additions & 0 deletions Sprint-2/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// ~ pad function will also be called three 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?
// ~ The value assigned to num will be the argument value 61

// c) What is the return value of pad is called for the first time?
// ~ The return value will be '01'

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// ~ The return value is 1 because the seconds input will subtract the remainingSeconds which is 1 and then divide the resultant value by 60, so the answer will give 1.

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// ~ The return value is '01' because it will be calculating the remaining seconds which is 1 and as such the pad method will add 0 to it.