Skip to content

ITP JAN25 | KATARZYNA_KAZIMIERCZUK | STRUCTURING_AND_TESTING_DATA | SPRINT2 #434

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 10 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
17 changes: 13 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// Predict and explain first...
// =============> write your prediction here
//
// function to capitalize the first letter of a string passed as a parameter

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
//str has been declared as a param befre being declared

// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }
console.log(capitalise("string"));
// =============> write your explanation here
//it happens because tstr is declared twice

// =============> write your new code here
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}

// =============> write your explanation here
// =============> write your new code here
6 changes: 6 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// decimal number has been declared in the funcion scope as a param
// and is not accessible outside of the function scope to console.log it will throw an error

// Try playing computer with the example to work out what is going on
decimalNumber = 0.5;

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
Expand All @@ -13,8 +16,11 @@ function convertToPercentage(decimalNumber) {
}

console.log(decimalNumber);
console.log(convertToPercentage(decimalNumber));

// =============> write your explanation here
// decim alNumber has to be availabke outside of the function scope to log its value

// Finally, correct the code to fix the problem
// =============> write your new code here
console.log(decimalNumber);
17 changes: 10 additions & 7 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
// 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) {
return num * num;
}
//a number value is hardcoded in the param instead of passing a reference to a parameter
// function square(3) {
// return num * num;
// }

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

// SyntaxError: Unexpected number
// =============> explain this error message here

//the function expected a parameter but instead a number was passed
// Finally, correct the code to fix the problem

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


console.log(square(2))
15 changes: 11 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Predict and explain first...

// =============> write your prediction here
//function does not run but is prining the resut into console

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

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

// =============> write your explanation here
// return the result

// Finally, correct the code to fix the problem
// =============> write your new code here
const multiply = (a, b) => a*b

multiply(10, 32)

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
16 changes: 10 additions & 6 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Predict and explain first...
// =============> write your prediction here
//return is befror ethe operation and the calculation is a dead code
// function sum(a, b) {
// return;
// a + b;
// }

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

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

// =============> write your explanation here
// return a+b
// Finally, correct the code to fix the problem
// =============> write your new code here

const sum = (a,b) => a+b
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
30 changes: 22 additions & 8 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@

// Predict the output of the following code:
// =============> Write your prediction here
//num is hardcoded and the function will return the same value each time
// const num = 103;

const num = 103;
// function getLastDigit() {
// return num.toString().slice(-1);
// }

function getLastDigit() {
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)}`);
// 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
// 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
//num is not reassigned each time the function runs

// Finally, correct the code to fix the problem
// =============> write your new code here
// const num = 103;

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
11 changes: 8 additions & 3 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// 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) {
// return the BMI of someone based off their weight and height
}
function calculateBMI(weight, heightM) {
// return parseFloat(weight / (heightCM * heightCM)).toFixed(1); this was returning a string because toFixed(1) returns a string
return Number((weight / (heightM * heightM)).toFixed(1)); // here the string is converted to a number
}

// const calculateBMI = (weight, height) => Number((weight / (heightM * heightM)).toFixed(1));

console.log(calculateBMI(59, 167));
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

const convertToUpper = (word) =>
word.replace(/ /g, "_").console.log(convertToUpper("kaska"));

console.log(convertToUpper("hello hi hi"));
31 changes: 31 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,34 @@
// 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 = (costInPence) => {
const penceStringWithoutTrailingP = costInPence.substring(0, costInPence.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('399p'))


// 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");

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

6 changes: 5 additions & 1 deletion Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ 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:

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// 0 // 60 was a typos*

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// it is a string "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
1 change: 1 addition & 0 deletions Sprint-3/fModule-Structuring-and-Testing-Data
Submodule fModule-Structuring-and-Testing-Data added at 5e6f17
Loading