Skip to content
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

Nw6|Aman-matoo/Module-Js1 Week:3 #189

Open
wants to merge 7 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
5 changes: 3 additions & 2 deletions week-1/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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.
// to solve this problem to make this line as commit //
Copy link

Choose a reason for hiding this comment

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

👍

Copy link
Author

Choose a reason for hiding this comment

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

yeah, this just has gone my mistake, I didn't want to be pushed.

5 changes: 3 additions & 2 deletions week-1/errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
console.log(age);
Copy link

Choose a reason for hiding this comment

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

👍


5 changes: 3 additions & 2 deletions week-1/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
Copy link

Choose a reason for hiding this comment

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

👍


//console.log ('I was born in ${city0fBirth}');//
3 changes: 2 additions & 1 deletion week-1/errors/3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = String (cardNumber).slice(-4);
console.log(last4Digits);
Copy link

Choose a reason for hiding this comment

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

👍


// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
Expand Down
4 changes: 2 additions & 2 deletions week-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const HourClockTime24 = "20:53";
const hourClockTime12 = "08:53";
Copy link

Choose a reason for hiding this comment

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

👍

2 changes: 1 addition & 1 deletion week-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let count = 0;

count = count + 1;

//line 3 describe
// 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
11 changes: 10 additions & 1 deletion week-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@

const num = 56.5467;

// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
// You should look up Math functions for this exercise https://developer.mozilla.o/rg/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num )
// Create a variable called decimalPart and assign to it an expression that evaluates to 0.5467 ( the decimal part of num )
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number )

// Log your variables to the console to check your answers

const wholeNumberPart =Math.floor(num)

console.log(wholeNumberPart);
const decimalPart=num-wholeNumberPart
console.log(decimalPart);
const roundedNum=Math.round(num)
console.log(roundedNum);
Copy link

Choose a reason for hiding this comment

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

👍


13 changes: 10 additions & 3 deletions week-1/exercises/initials.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";
let firstName = "creola";
let middleName = "katherine";
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
let firstInitial = firstName.charAt(0).toUpperCase();
console.log(firstInitial);
let middleInitial = middleName.charAt(0).toUpperCase();
console.log(middleInitial);
let lastInitial = lastName.charAt(0).toUpperCase();
console.log(lastInitial);
console.log(`${firstInitial}.${middleInitial}.${lastInitial} `);
Copy link

Choose a reason for hiding this comment

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

Looks great :)

6 changes: 5 additions & 1 deletion week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);

console.log(lastSlashIndex);
// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
let = filePath ("/")
console.log (dirPart,filePath);
const
console.log(filePath+ lastSlashIndex)
Copy link

Choose a reason for hiding this comment

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

this file needs finished - feel free to ask if you're unsure what to do

3 changes: 3 additions & 0 deletions week-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// Try breaking down the expression and using documentation to explain what it means
// It will help to think about the order in which expressions are evaluated
// Try logging the value of num several times to build an idea of what the program is doing
const minImum = Math.floor(sum)
Copy link

Choose a reason for hiding this comment

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

Haven't answered the question here I'm afraid. It's asking what value num is currently?

Copy link
Author

Choose a reason for hiding this comment

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

yeah, has just gone by, a mistake I didn't want to push it

let.Math.floor(Math.random() * 6 + 1);
console.log(minImum);
6 changes: 4 additions & 2 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

There are four function
line 1 line 2 , line line 7 and line 8
Copy link

Choose a reason for hiding this comment

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

Those lines aren't function calls I'm afraid: they're varible assignments. Have a look at the MDN docs to remind yourself https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions There are infact five diffrent function calls in bthe function. Can you see them?

// b) Identify all the lines that are variable reassignment statements

line 1 is carpeice line 2 is priceAfterOneYear , line 7 priceDifference line 8 priceDifference
Copy link

Choose a reason for hiding this comment

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

The keyword here is reassignment statements - that is a statement where a varible's value is changed. There are two of these in the code. Can you find them?

// c) Identify all the lines that are variable declarations
var to 10000 , var is "8553" , var 7 is carPrice -priceAfterOneYear and var 8 priceDifference / carPrice
Copy link

Choose a reason for hiding this comment

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

Varible declarations are the lines where you use var or let to create a varible (const creates a contant techincally), so I'm afraid this isn't the answer I'm looking for


// d) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
Copy link

Choose a reason for hiding this comment

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

Need an answer to this please!

2 changes: 1 addition & 1 deletion week-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ console.log(result);
// For the piece of code above, read the code and then answer the following questions
Ayman-matoo marked this conversation as resolved.
Show resolved Hide resolved

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

there are seven variable declared
// b) How many function calls are there?

// c) Using documentation on MDN, explain what the expression movieLength % 60 represents
Expand Down
6 changes: 5 additions & 1 deletion week-2/errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// 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)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;

return str;

}
console.log(capitalise("bule"));
// variable name without let
Copy link

Choose a reason for hiding this comment

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

This is what solved the problem. Could you tell me why this solved the problem?

3 changes: 3 additions & 0 deletions week-2/errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ function convertToPercentage(decimalNumber) {
}

console.log(decimalNumber);
// you can't declare constant with the same name as a parameter within the same scope
// decimalNumber is not defined.
// value numbers should not take string
Copy link

Choose a reason for hiding this comment

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

The first one is right but I'm not so sure about the other two. They shouldn't be issues at all - JS converts strings to numbers automatically.

Copy link
Author

Choose a reason for hiding this comment

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

okay, thank you for the feedback.

10 changes: 7 additions & 3 deletions week-2/errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
// 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;
}
function square (num) {
return num * num;

}

console.log("square" (8));
Copy link

Choose a reason for hiding this comment

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

You've solved the problem above but this line is a little confused. You aren't actually calling the function. What does this console.log statement log?




8 changes: 8 additions & 0 deletions week-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
// 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 bim (weigh,height){
height = height*weigh;
let bim = ("weigh*height");
Copy link

Choose a reason for hiding this comment

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

This function is quite wrong I'm afraid, please give it another crack. You need to ensure you're following the instructions. You'll figure it out :)


}

console.log(bim);
15 changes: 15 additions & 0 deletions week-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@
// When we call this function with the input string
// Then it returns the string in UPPER_CAMEL_CASE, so "HELLO_THERE"


function cases (str){
str =`${str.Uppercase()}`
str =`${str.Snake_cases()}`
Copy link

Choose a reason for hiding this comment

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

snake_cases() is not a function. You need to impliment the snake casing on your own I'm afraid (hint: have a look at string methods especailly replace - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).

Please ensure you are actually running your code to ensure it works before submitting.

return
}
console.log("cases");

// Test case: we expect "lord of the rings" to be "LORD_OF_THE_RINGS"
// Test case: we expect "the great gatsby" to be "THE_GREAT_GATSBY"
// Test case: we expect "the da vinci code" to be "THE_DA_VINCI_CODE"

// Come up with a clear, simple name for the function
// Use the string documentation to help you plan your solution







6 changes: 6 additions & 0 deletions week-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
// 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(jainnah){
return `${Number( jainnah / 1200).toFixed(2)} pounds`;
Copy link

Choose a reason for hiding this comment

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

This code runs but I'm afraid it's wrong - there are 100 pennies in a pound not 1200 We also need to handle non numbers by throwing an error

Copy link
Author

Choose a reason for hiding this comment

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

okay thank for explanation



}
console.log(toPounds(20));
5 changes: 5 additions & 0 deletions week-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
// Given a number,
// When I call this function with a number
// Then it returns the new price with VAT added on
function addVat(price){
price*1.2
result(price);
}
console.log(addVat(150));
18 changes: 18 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,21 @@
// 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(angle){
if (angle==90){
return "right angle";
} else if(angle < 90){
return "acute angle";
} else if (angle == 180){
return "straight angle";
} else if (angle >90 && angle <180){
return "obtuse angle";
} else if (angle >180 && angle <360){
return "reflex angle";
} else {
return "invalid";
Copy link

Choose a reason for hiding this comment

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

Looks great, well done!

Copy link
Author

Choose a reason for hiding this comment

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

thank you

}
}
console.log(getAngleType(90));
16 changes: 16 additions & 0 deletions week-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@
// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
function getCardValue(card){
const rank = card.slice(0,-1)
if (rank >=2 && rank<= 10){
return parseInt(rank);
Copy link

Choose a reason for hiding this comment

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

I wouldn't expect you to know this at this level but here's a bit of context if you are intrested. Feel free to ignore this if it doesn't make sense

This could cause errors. JavaScript's string conversion can be dodgy. I would make this the last thing we do, and use parseInt() before comparing rank so it fails fast

}
if (["j" ,"Q","R"].includes(rank)){
return 10;
}
if (rank =="A"){
return 11;
}
else {
return "invalid card rank"
}
}
console.log("getCardValue()");
26 changes: 26 additions & 0 deletions week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,29 @@
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.

// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator.

// Define the function
function isProperFraction(numerator, denominator) {
var x = numerator;
var y = denominator;

var outputVal = x % y;
if (outputVal > 0) {
Copy link

Choose a reason for hiding this comment

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

We need a few more checks to meet the requirements - have a nother look if you have a mo

return false;
} else {
return true;
}
}

// Call the function with some example values
var numeratorExample = 14;
var denominatorExample = 2;

var result = isProperFraction(numeratorExample, denominatorExample);

// Log the result to the console
if (result === true) {
console.log("target output: true");
} else {
console.log("target output: false");
}
12 changes: 12 additions & 0 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@
// Then it should return true because the input forms a valid triangle.

// This specification outlines the behavior of the isValidTriangle function for different input scenarios, ensuring it properly checks for invalid side lengths and whether they form a valid triangle according to the Triangle Inequality Theorem.

function isValidTriangle(a, b, c) {
if (a <= 0 || b <= 0 || c <= 0) {
return "false";
} ;
if (a - b <= c || a + c <= b || b + c <= a) {
Copy link

Choose a reason for hiding this comment

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

👍

Copy link
Author

Choose a reason for hiding this comment

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

thank you

return "false";
else {
return true;
}
}
console.log(isValidTriangle(3, 7, 2));
16 changes: 16 additions & 0 deletions week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@
// Store this expression in a variable and reference it twice in the function in the correct place

// Explain why it makes more sense to store this expression in a variable

function formatAs12Hours(time) {
const hours24 = Number(time.slice(0, 2));

if (hours24 < 0 || hours24 > 23) {
return "Invalid hours in time string"; // check vaild in 24hours fromat
} else if (hours24 === 0) {
return "midnight";
Copy link

Choose a reason for hiding this comment

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

This wouldn't be an exspected output - if you are exspecting hours:minutes midnight would be an annoying output

} else {
const hours12 = hours24 % 12;
const period = hours24 < 12 ? "AM" : "PM";
return `${hours12 === 0 ? 12 : hours12}:${time.slice(3)} ${period}`;
Copy link

Choose a reason for hiding this comment

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

Looks good 👍

}
}

console.log(formatAs12Hours("08:30")); // Example usage
2 changes: 1 addition & 1 deletion week-3/refactor/is-vowel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function isVowel(letter) {
return (
letter === "a" ||
letter === "e" ||
letter === "i" ||
// letter === "i" ||
Copy link

Choose a reason for hiding this comment

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

👍

Copy link
Author

Choose a reason for hiding this comment

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

thank you

letter === "i" ||
letter === "o" ||
letter === "u"
Expand Down