Skip to content

Module-Structuring-and-Testing-Data sprint2 Nurzat Nurdinova #622

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

// The code will throw an error because the variable `str` is being declared twice in the same scope.

// 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)}`;
return str;
}
capitalise("hello,this is a test");

//

// =============> write your explanation here
// =============> write your new code here
//// The error occurs because the variable `str`is declared twice in the same scope,which is not allowed in JavaScript.
10 changes: 10 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
//Decimal number is undefined
//we ll got syntax error as we are declaring a new variable

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

Expand All @@ -18,3 +20,11 @@ console.log(decimalNumber);

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {

const percentage = `${decimalNumber * 100}%`;

return percentage;
}

result = console.log(convertToPercentage(0.5));
14 changes: 13 additions & 1 deletion Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@

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

//we will get an error bcs the parameter of the function need to string type not number so it can be something like num

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

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

/index.js:1
function square(3) {
^

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

// Finally, correct the code to fix the problem

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


//THe error message tells that we wrote a syntax that JavaScript does not understand.
function square(num) {
return num * num;
}
result = console.log(square(3));
10 changes: 8 additions & 2 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Predict and explain first...

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

// What I predict is that the console.log which is outside the function will pass the parameters 10 and 32 to the function
// Then the console.log(a * b) which is inside the function will print out
// to the terminal the multiplication of a by b
function multiply(a, b) {
console.log(a * b);
const multiplicationResult = (a * b);
return multiplicationResult;



}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
Expand Down
9 changes: 6 additions & 3 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Predict and explain first...
// =============> write your prediction here

// The code will not return the sum of the two numbers because the return statement is placed before the actual addition operation.
function sum(a, b) {
return;
a + b;
return a + b;


}

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
//
12 changes: 11 additions & 1 deletion Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

// The code will not retuen the last digit of the number because the function getLastDigit is not correctly defined to aacept the parameter.
const num = 103;

function getLastDigit() {
Expand All @@ -16,9 +16,19 @@ 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
// Because every time we are passing the parameters we are actually using the num value and return it.
// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> 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
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)}`);
5 changes: 4 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,8 @@
// 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
squareHeight =height * height;
bmi = weight / squareHeight;
return bmi.0toFixed(1);

}
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 upperSnakeCase(str) {
return (upperSnakeCase = str.replaceAll(" ", "_").toUpperCase());
}
console.log(upperSnakeCase("Congratulations having a boy! 🎉"));
6 changes: 6 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,9 @@
// 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(kg) {
const pounds =kg *2.20462;
return pounds.toFixed(2);

}
1 change: 1 addition & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
//