-
-
Notifications
You must be signed in to change notification settings - Fork 196
London | May-2025 | Reza Jahanimir | Coursework/sprint 2 #524
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
base: main
Are you sure you want to change the base?
Changes from all commits
4537db5
2c8408a
e07fba5
b5673e8
1051cc6
12ef9ff
24fbd12
3d2dea4
390e02d
6ec7ff0
8bd0b69
cac6f1a
7a30ff0
01bd659
30743d2
b405e12
7fb1e48
b4cedf8
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,13 +1,24 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// =============> this function takes a string and capitalize the first letter of each word, | ||
// then returns the modified string. However. if the first character is a space or a number, | ||
// the function must validate this edge case before processing to avoid unexpected results. | ||
|
||
// 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; | ||
} | ||
}; | ||
|
||
// =============> write your explanation here | ||
console.log(capitalise("reza")); | ||
|
||
// =============> the parameter name and the variable are the same while causes this error | ||
// =============> write your new code here | ||
|
||
function capitalise(str) { | ||
const cap_string = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return cap_string; | ||
}; | ||
|
||
console.log(capitalise("reza")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// the console.log inside the function will run but the one in global will raise the undefine error | ||
// we will get an undefine error because we are not retuning the value | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
|
@@ -9,6 +11,13 @@ function multiply(a, b) { | |
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// To use the final result of a function, we must return the value. Otherwise, it will raise an undefined error. | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
function multiply(a, b) { | ||
const result = a * b; | ||
return result; | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
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 provided the right solution here, with a simple suggestion. The |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,9 @@ | |
// 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 | ||
} | ||
const height_squared = height * 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. Simple solutions that are simple to read are always good code, which you have done here. Just want to draw your attention to some built-in methods that JavaScript has for this same thing https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow |
||
const bmi = height_squared / weight; | ||
return bmi.toFixed(1); | ||
} | ||
|
||
console.log(calculateBMI(83, 180)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,18 @@ | |
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. | ||
|
||
function formatAs12HourClock(time) { | ||
const hours = Number(time.slice(0, 2)); | ||
if (hours > 12) { | ||
return `${hours - 12}:00 pm`; | ||
const [hourStr, minuteStr] = time.split(":"); | ||
const hours = Number(hourStr); | ||
|
||
let period = hours >= 12 ? "pm" : "am"; | ||
let displayHour = hours % 12; | ||
if (displayHour === 0) { | ||
displayHour = 12; // Handles 00:xx (midnight) and 12:xx (noon) | ||
} | ||
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. Your solution is returning You need to take a look at the original question again and see how you can do that 🙂 |
||
return `${time} am`; | ||
// If you input "08:00" is allowed to pass | ||
const paddedHour = hourStr.length === 2 && displayHour < 10 ? `0${displayHour}` : `${displayHour}`; | ||
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. Nice work in formatting the hour it is returned. I have a resource that you might want to consider should you need to do this again in the future |
||
|
||
return `${paddedHour}:${minuteStr} ${period}`; | ||
} | ||
|
||
const currentOutput = formatAs12HourClock("08:00"); | ||
|
@@ -23,3 +30,10 @@ console.assert( | |
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
); | ||
|
||
console.assert(formatAs12HourClock("00:00") === "12:00 am", "Midnight failed"); | ||
console.assert(formatAs12HourClock("01:00") === "01:00 am", "1am failed"); | ||
console.assert(formatAs12HourClock("08:00") === "08:00 am", "8am failed"); | ||
console.assert(formatAs12HourClock("12:00") === "12:00 pm", "Noon failed"); | ||
console.assert(formatAs12HourClock("13:00") === "01:00 pm", "1pm failed"); | ||
console.assert(formatAs12HourClock("23:00") === "11:00 pm", "11pm failed"); |
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.
This is a simple and straight forward explanation, nice job