Skip to content

Sprint 2 #146

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 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c36d5b3
Debug exercise 0.js undefined function values
Della-Bella Nov 11, 2024
fe4ebe8
Debug error line "return"
Della-Bella Nov 11, 2024
03b3c5e
Debug 2.js.The function don't have a parameter to receive the variabl…
Della-Bella Nov 12, 2024
6dc1cb6
my practice exercise/ explain assert
Della-Bella Nov 12, 2024
5e34bb5
SyntaxError: Identifier 'str' has already been declared/ defined corr…
Della-Bella Nov 12, 2024
856a3f5
Fixed error function name/ 3 is not a valid name
Della-Bella Nov 12, 2024
3cbc91a
Fixed Function name error/ 3 is not a valid name
Della-Bella Nov 12, 2024
f2a9162
Format Time console.assert practice
Della-Bella Nov 12, 2024
a271680
Practice Function UpperCase
Della-Bella Nov 12, 2024
b069435
Practicing Function toUpperCase
Della-Bella Nov 12, 2024
1de6b0f
Applying Function toUpperCase
Della-Bella Nov 12, 2024
2d6c264
Code function to add % on a value number
Della-Bella Nov 13, 2024
5930178
Function Vat add % to a number
Della-Bella Nov 13, 2024
bfdb3fb
Add Comments to a line in java Script //
Della-Bella Nov 13, 2024
4116ead
Creating Function BMI
Della-Bella Nov 14, 2024
11078e5
creating Function bmi
Della-Bella Nov 14, 2024
e8723c0
code revision
Della-Bella Nov 14, 2024
3e7b813
Function Time Formatting explained
Della-Bella Nov 15, 2024
1b49ee2
Interpreting Time Formatting Function
Della-Bella Nov 15, 2024
32dfaaa
Interpreting Function Time formatting
Della-Bella Nov 15, 2024
2bbcf99
Function to.pound reusable block
Della-Bella Nov 15, 2024
7ce5b80
Revising function % vat
Della-Bella Nov 15, 2024
6f78ed9
Debugging the error
Della-Bella Dec 21, 2024
661fd6d
Fixing function returning the Sum
Della-Bella Dec 21, 2024
17f8b03
Fix it
Della-Bella Dec 21, 2024
9b2ceee
Declared the function
Della-Bella Dec 21, 2024
17d1618
Removed the duplicated declaration
Della-Bella Dec 21, 2024
f519e88
Fixing changing the name of the function.
Della-Bella Dec 21, 2024
8631aae
Fix the units/ removed the constant values
Della-Bella Dec 21, 2024
d4486d6
Fix the function convert numbers to 12 hours format
Della-Bella Dec 21, 2024
616ef23
shor wat to implemeting ++1 = count++;
Della-Bella Dec 21, 2024
a8316b9
Fix the count++;
Della-Bella Dec 21, 2024
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: 6 additions & 2 deletions Sprint-1/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
//This is just an instruction for the first activity - but it is just for human consumption
//We don't want the computer to run these 2 lines - how can we solve this problem?

// add comets for Line use //
/* comments for many lines
can use */
2 changes: 1 addition & 1 deletion Sprint-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let count = 0;

count = count + 1;
count++;;

// 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
25 changes: 25 additions & 0 deletions Sprint-2/debug/0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
// Predict and explain first...

/*it will print
the first console.log (a * b) which will call the function inputs 10, 32 = 320
function multiply(a, b) {
console.log(a * b);
}

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

DEBUG*/

//The result of multiplying 10 and 32 is 320
Copy link
Member

Choose a reason for hiding this comment

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

Did this prediction bear out, or did it print undefined? Why did it do this?

Copy link
Author

Choose a reason for hiding this comment

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

The function wasn't called initially, so it didn't display the result. However, it has now been called and is returning the result.


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

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

// The function wasn't called initially, so it didn't display the result.
// //However, it has now been called and is returning the result.










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

/*It will print a error as return is in one line and Javasript will Not
read any code after that line


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

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

//FIX://

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

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

//The result wasn't returned because the sum of a and b wasn't included.
//Now I have fixed the code, and it is returning the result
42 changes: 39 additions & 3 deletions Sprint-2/debug/2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
// Predict and explain first...

const num = 103;
//const num = 103;

function getLastDigit(numLast) {
return numLast.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.
the function doesn’t have a parameter to receive the num variable it’s trying to process.
Copy link
Member

Choose a reason for hiding this comment

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

This is true, but not complete. It doesn't have a parameter, so why is it returning 3? Where does the 3 come from?

Copy link
Author

Choose a reason for hiding this comment

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

The function was using the same variable every time. Adding a parameter to the function fixed it.T

// Explain why getLastDigit is not working properly - correct the problem
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)}`);



function getLastDigit() {
return num.toString().slice(-1);
}*/
// FIX

/*const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
Expand All @@ -10,5 +38,13 @@ 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
function getLastDigit() {
return num.toString().slice(-1);
}

gisdellabella@Giss-MBP debug % node 2.js
The last digit of 42 is 3
The last digit of 105 is 3
The last digit of 806 is 3
42
gisdellabella@Giss-MBP debug */
18 changes: 17 additions & 1 deletion Sprint-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

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

Error: SyntaxError: Identifier 'str' has already been declared

Fix:*/

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

console.log(`${capitalise(" change this text to uppercase " )}`);


/*gisdellabella@Giss-MBP errors % node 0.js
CHANGE THIS TEXT TO UPPERCASE change this text to uppercase
gisdellabella@Giss-MBP errors %*/
9 changes: 7 additions & 2 deletions Sprint-2/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
// Why will an error occur when this program runs?
// Try playing computer with the example to work out what is going on
Copy link
Member

Choose a reason for hiding this comment

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

What do you think? Why is this happening? What is the fix?

Copy link
Author

Choose a reason for hiding this comment

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

Remove the duplicated declaration. With this commit



function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;

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

return percentage;
}

console.log(decimalNumber);
console.log(0.5);

// const decimalNumber = 0.5;
// ERROR: SyntaxError: Identifier 'decimalNumber' has already been declared

11 changes: 7 additions & 4 deletions Sprint-2/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

// Predict and explain first...

// this function should square any number but instead we're going to get an error
function square(num) {
return num * num;

function square(3) {
return num * num;
}
}
console.log (square (3))



//The error was with parameter 3, which always gave me the same result.
// By changing it to "num," the function now works with any number. Also 3 is used as the parameter name for the function, which is not valid in JavaScript.
49 changes: 49 additions & 0 deletions Sprint-2/extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,52 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

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


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

const currentOutput5 = formatAs12HourClock ("01:00");

const targetOutput5= "01:00 am";

console.assert(
currentOutput5 === targetOutput5,
`curent output: ${currentOutput5}, target output: ${targetOutput5}`
)

const currentOutput6 = formatAs12HourClock ("04:00");
const targetOutput6= "04:00 am";
console.assert(
currentOutput6 === targetOutput6,
`curent output: ${currentOutput6}, target output: ${targetOutput6}`
)


const currentOutput7 = formatAs12HourClock("22:00")
const targetOutput7 = "10:00 pm";

console.assert(
currentOutput7 === targetOutput7,
`curent output: ${currentOutput7}, target output: ${targetOutput7}`

)

const currentOutput9 = formatAs12HourClock("00:00")
const targetOutput9 = "00:00 am";
console.assert(
currentOutput9 === targetOutput9,
`curent output: ${currentOutput9}, target output: ${targetOutput9}`

)
18 changes: 18 additions & 0 deletions Sprint-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@
// 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 weight = 150;
// const height = 170 / 100; //tranforme centimeter to meter


function ibmCalculator( weight, height) {

height = height / 100;
let calculateIBM = weight / Math.pow(height, 2);
let result = calculateIBM.toFixed(1); //chang for decimal
return result;
}


console.log(`Your Body Mass Index (BMI) is ${ibmCalculator(98,126)}`);


12 changes: 12 additions & 0 deletions Sprint-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@

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


// my fucntion

function upperSnakeCase(upperCaseTexts) {
return upperCaseTexts.toUpperCase().replace(/\s+/g, '_');
}

console.log(`${upperSnakeCase("hello there")}`);

//gisdellabella@Giss-MBP implement % node cases.js
// HELLO_THERE
54 changes: 54 additions & 0 deletions Sprint-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,57 @@
// 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 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");
}
const penceString = "399p";
console.log(`£${pounds}.${pence}`);*/

function toPounds(penceString) {
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
); // Remove the "p"

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // make sure number string has at least 3 digits

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
); // Extract pounds and pence

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

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

const result1 = toPounds("799p");
const result2 = toPounds("50p");
const result3 = toPounds("5230p");
const result4 = toPounds("545p");
console.log(result1);
console.log(result2);
console.log(result3);
console.log(result4);

gisdellabella@Giss-MBP implement % node to-pounds.js
£7.99
£0.50
£52.30
£5.45
12 changes: 12 additions & 0 deletions Sprint-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@
// Given a number,
// When I call this function with a number
// it returns the new price with VAT added on

function addPercentageToPrice(price) {
let vat = price * 1.2;
return vat;
}

let price = 675;
console.log(`Product total price is ${addPercentageToPrice(price)}`);

//let price = 30; Product total price is 36
//let price = 45; Product total price is 54
//let price = 45; Product total price is 810
Loading