Skip to content

ITP JAN|saraamiri|Module-structuring-and-testing-data |sprint 2 #346

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
8 changes: 7 additions & 1 deletion Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
// interpret the error message and figure out why an error is occurring

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

// =============> write your explanation here
//we recieve an syntax error beacuse we use str as parameter and then use as variable we can not do the same in js
// =============> write your new code here
//to fix this i remove the let ,dont need to declare new variable str
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
7 changes: 7 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ console.log(decimalNumber);

// Finally, correct the code to fix the problem
// =============> write your new code here
//we need to remove redeclaration of decimal number inside the function
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}

console.log(convertToPercentage(0.5));
15 changes: 9 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

// =============> write your prediction of the error here

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

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

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

//we need to define the parameter in the function as num
// Finally, correct the code to fix the problem

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


function square(num) {
return num * num;
}
console.log(square(3));
9 changes: 8 additions & 1 deletion Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ function multiply(a, b) {
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

//the problem is multiply function dose 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)}`);
6 changes: 6 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
//return and a+b in 2 seprate line,he line a + b; is effectively unreachable and will not be executed.
// 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)}`);
7 changes: 7 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ 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
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)}`);
13 changes: 12 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@
// 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
}

// Step 1: Square the height
const heightSquared = height * height;

// Step 2: Divide weight by the squared height to calculate BMI
const bmi = weight / heightSquared;

// Step 3: Return the BMI rounded to 1 decimal place
return bmi.toFixed(1);
}
Comment on lines +21 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

What type of value do you think the function should return? A number or a string?
Does your function return the type of value you think it should return?

Suggestion: You may want to lookup "How to check the data type of a value in JS".

7 changes: 7 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,10 @@
// 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) {
// Split the string into words, convert each word to uppercase, and join them with underscores
return str.split(' ').map(word => word.toUpperCase()).join('_');
}

console.log(toUpperSnakeCase("hello there")); // Output: "HELLO_THERE"
console.log(toUpperSnakeCase("lord of the rings")); // Output: "LORD_OF_THE_RINGS"
26 changes: 26 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,29 @@
// 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 to convert pence string to pounds
function toPounds(penceString) {
// Remove the trailing "p" from the input string
const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);

// Pad the number to ensure it's at least 3 digits
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

// Extract the pounds (first part of the string)
const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);

// Extract the pence (last two digits), ensuring it's two digits
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

// Return the formatted result
return `£${pounds}.${pence}`;
}

// Test the function with different inputs
console.log(toPounds("399p")); // Expected output: £3.99
console.log(toPounds("100p")); // Expected output: £1.00
console.log(toPounds("25p")); // Expected output: £0.25
console.log(toPounds("500p")); // Expected output: £5.00

8 changes: 5 additions & 3 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> write your answer here 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?
// =============> write your answer here

//zero
// c) What is the return value of pad is called for the first time?
// =============> write your answer here
//num is zero and pad will be "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
// =============> write your answer here is call for remaining second will be 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
//The return value assigned to num when pad is called for the last time will be "01", because pad(1) will return "01"