Skip to content

Commit

Permalink
i fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
nohetekelmariyam committed Dec 2, 2023
1 parent ac4dc6c commit 6e6ede5
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 33 deletions.
6 changes: 4 additions & 2 deletions week-1/exercises/initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ let lastName = "Johnson";

// Declare a variable called initials that stores the first character of each string in upper case to form the user's initials
// Log the variable in each case
var initials= `${firstName.charAt(0).toUpperCase()} ${middleName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`;
console.log(initials)
var initials = `${firstName.charAt(0).toUpperCase()} ${middleName
.charAt(0)
.toUpperCase()}${lastName.charAt(0).toUpperCase()}`;
console.log(initials);
8 changes: 5 additions & 3 deletions week-1/interpret/percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ console.log(`The percentage change is ${percentageChange}`);
// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made

//2 Number and replaceAll
// b) Identify all the lines that are variable reassignment statements

//line 4,5
// c) Identify all the lines that are variable declarations

//line 1,2,7,8
// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//Number(carPrice.replaceAll(",","")) is doing first variable carPrice ..
//..is a string, so function Number change this string in to num and function replaceAll change all , in to ..
12 changes: 7 additions & 5 deletions week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ console.log(result);
// For the piece of code above, read the code and then answer the following questions

// a) How many variable declarations are there in this program?

//there are 7 variable in this pice of code
// b) How many function calls are there?

// we don't have function here
// c) Using documentation on MDN, explain what the expression movieLength % 60 represents

//remainingSeconds = movieLength % 60;=> this expression is ..
//..help us to get the remaining second after variable movieLength divide by 60
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// totalMinutes assign to change moveLength in to minutes by subtract from movieLength
// e) What do you think the variable result represents? Can you think of a better name for this variable?

//result represent the remainingHours, remainingMinutes and the remainingSeconds
//i suggest replacing the variable name "result" with "remainingHours" to enhance clarity.
// f) Think about whether this program will work for all values of movieLength.
// Think of what values may cause problems for the code.
// Decide the result should be for those values, then test it out.
Expand Down
9 changes: 6 additions & 3 deletions week-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const penceString = "399p";

// "penceSting" variable declare with "399p" value
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

// "penceStringWithoutTrailingP" is create new value by taking substring from "penceString"
// function subString remove the last index by subtract -1 from "penceString"length
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
//paddedPenceNumberString is create a value by add 0 in "penceStringWithoutTrailingP"
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

//"pounds" is create a value by taking subString from "paddedPenceNumberString"
//function subString remove the last index by subtract -2 from "paddedPenceNumberString"length
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
Expand Down
4 changes: 3 additions & 1 deletion week-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// interpret the error message and figure out why it's happening, if your prediction was wrong

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
var str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
var str = "uygugbu";
console.log(capitalise(str));
10 changes: 4 additions & 6 deletions week-2/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

// Predict and explain first...
// this function should square any number but instead we're going to get an error
// what is happening? How can we fix it?

function square(3) {
return num * num;
// to obtain the first square number we need multiply a number by it self
function square(num) {
return num * num;
}


console.log(square(2));
12 changes: 12 additions & 0 deletions week-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
// Given someone's weight in kg and height in metres
// When we call this function with the weight and height
// Then it returns their Body Mass Index to 1 decimal place
function bmiCalculation(weight, height) {
if (typeof weight === "number" && typeof height === "number") {
const bmi = weight / (height * height);

return `${bmi.toFixed(1)}`;
} else {
return " please use the right unit";
}
}
var weight = 60;
var height = 1.64;
console.log(bmiCalculation(weight, height));
8 changes: 8 additions & 0 deletions week-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@

// Come up with a clear, simple name for the function
// Use the string documentation to help you plan your solution
let string = "";
function upperSnakeCase(string) {
const wordSplit = string.split(" ");
const wordToCapital = wordSplit.map((word) => word.toUpperCase());
const wordJoin = wordToCapital.join("_");
return wordJoin;
}
console.log(upperSnakeCase("nohe tekel mariyam"));
18 changes: 18 additions & 0 deletions week-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@
// Take this code and turn it into a reusable block of code.
// Declare a function called toPounds with an appropriately named parameter.
// 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");
return ${pounds}.${pence}`;
}
var penceString = "299p";
console.log(toPounds(penceString));
13 changes: 12 additions & 1 deletion week-2/implement/vat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// When selling goods, most are subject to the 20% standard rate of VAT.
// You must add 20% to the price you charge for the goods.
// You can do this by multiplying the price you charge by 1.2.
// For example, if your business sells sports equipment for £50, you multiply £50 by 1.2 for a total VAT inclusive price of £60.
// For example, if your business sells sports equipment for £50, you multiply £50 by 1.2 for ..
//..a total VAT inclusive price of £60.

// Implement a function that calculates the new price with VAT (Value Added Tax) added on.

// Given a number,
// When I call this function with a number
// Then it returns the new price with VAT added on
function productCostWithVat(price) {
if (typeof price === "number") {
const vatPrice = price * 1.2;
return ${vatPrice.toFixed(2)}`;
} else {
return "don't waste my time";
}
}
var price = 399;
console.log(productCostWithVat(price));
14 changes: 9 additions & 5 deletions week-2/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ console.log(formatTimeDisplay(143));
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?

//3 time
// Call formatTimeDisplay with an input of 143, now answer the following:

// b) What value is assigned to the parameter num when pad is called for the first time?

//remainingHours or 00
// c) What is the return value of pad when it is called for the first time?

//00
// d) What is the value assigned to the parameter num when pad
// is called for the last time in this program? Explain your answer

//if second is less than 10 it would add 0 but now it is more than 10 so it return 23.
// e) What is the return value when pad is called
// for the last time in this program? Explain your answer

// pad return 23 b/c 23 is greater than 10
// f) Research an alternative way of padding the numbers in this code.
// Look up the string functions on mdn
/ //funtion pad(num)
//{
// return num.toString().padstart(2,"0");
//}
15 changes: 15 additions & 0 deletions week-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@
// Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
function getAngleType(Angles) {
if (Angles == 90) {
return "Right angle";
} else if (Angles < 90) {
return "Acute angle";
} else if (Angles == 180) {
return "Straight angle";
} else if (Angles > 180 && AngleS < 360) {
return "reflex angle";
} else {
return "it's not angle";
}
}
var AngleS = 350;
console.log(getAngleType(AngleS));
2 changes: 1 addition & 1 deletion week-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Given a card string in the format "A♠" (representing a card in blackjack),
// When the function getCardValue is called with this card string as input,
// Then it should return the numerical card value

function getCardValue() {}
// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "10",
// When the function is called with such a card,
Expand Down
14 changes: 13 additions & 1 deletion week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
// Input: numerator = 2, denominator = 3
// target output: true
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.

function isProperFraction(numerator, denominator) {
if (numerator >= denominator && denominator != 0) {
return "false";
} else if (numerator < denominator) {
return "True";
} else {
return "error";
}
}
console.log(isProperFraction(5, 2));
console.log(isProperFraction(3, 0));
console.log(isProperFraction(-4, 7));
console.log(isProperFraction(3, 3));
// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
Expand Down
27 changes: 22 additions & 5 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,36 @@
// It's also true that b + c > a
// It's also true that a + c > b

// In our function isValidTriangle, we need to return false for any triangle where the sum of any two sides is less than or equal to the length of the third side.
// and we need to return true for any triangle where the sum of any two sides is greater than the length of the third side.
// In our function isValidTriangle, we need to return false for any triangle where the sum of any two
//..sides is less than or equal to the length of the third side.
// and we need to return true for any triangle where the sum of any two sides is greater than the length
//..of the third side.

// Acceptance criteria:

// Given the lengths of three sides of a triangle (a, b, c),
// When the function isValidTriangle is called with these side lengths as input,
// Then it should:

function isValidTriangle(side1, side2, side3) {
if (
side1 + side2 <= side3 ||
side1 + side3 <= side2 ||
(side2 + side3 <= side1 && side1 <= 0) ||
side2 <= 0 ||
side3 <= 0
) {
return "false";
} else {
return "turn";
}
}
// scenario: invalid triangle
// Given the side lengths a, b, and c,
// When the sum of any two side lengths is less than or equal to the length of the third side (i.e., a + b <= c, a + c <= b, b + c <= a),
// Then it should return false because these conditions violate the Triangle Inequality, which states that the sum of the lengths of any two sides of a triangle must be greater than the length of the third side.
// When the sum of any two side lengths is less than or equal to the length of the third side
//.. (i.e., a + b <= c, a + c <= b, b + c <= a),
// Then it should return false because these conditions violate the Triangle Inequality,
//..which states that the sum of the lengths of any two sides of a triangle must be greater than the
//..length of the third side.

// scenario: invalid triangle
// Check for Valid Input:
Expand Down
14 changes: 14 additions & 0 deletions week-4/implement/creditCardValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//n this project you'll write a script that validates whether or not a credit card number is valid.

//Here are the rules for a valid number:

//- Number must be 16 digits, all of them must be numbers.
//- You must have at least two different digits represented (all of the digits cannot be the same).
//- The final digit must be even.
//- The sum of all the digits must be greater than 16.
function creditCardValidator(cardNumber) {
if (typeof cardNumber !== "number" && cardNumber.length !== 16);
{
return "not card";
}
}

0 comments on commit 6e6ede5

Please sign in to comment.