-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: main
Are you sure you want to change the base?
Changes from all commits
dcc0a14
f8bb6db
70a7f34
328e5cf
a54967b
1541dd8
f275546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 // | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
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}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
//console.log ('I was born in ${city0fBirth}');// |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
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 |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
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} `); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need an answer to this please! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, thank you for the feedback. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay thank for explanation |
||
|
||
|
||
} | ||
console.log(toPounds(20)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great, well done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you |
||
} | ||
} | ||
console.log(getAngleType(90)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good 👍 |
||
} | ||
} | ||
|
||
console.log(formatAs12Hours("08:30")); // Example usage |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ function isVowel(letter) { | |
return ( | ||
letter === "a" || | ||
letter === "e" || | ||
letter === "i" || | ||
// letter === "i" || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you |
||
letter === "i" || | ||
letter === "o" || | ||
letter === "u" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
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.