-
Notifications
You must be signed in to change notification settings - Fork 0
Javascript javascript1 week3 #5
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?
Conversation
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.
Great job on all assignments! You did a great job with arrays, objects and functions - the code works and it's shows that you understand the basic concepts. There were some small mistakes, but overall you are on the right track.
| function getNote(id) { | ||
| if (typeof id !== "number") { | ||
| console.log("Error: Invalid ID."); | ||
| return; |
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.
You can write here "return undefined" for clarity
| return; | |
| return undefined; |
And the error message can be made a little more specific (for example: "ID must be a number").
| const percentage = (seriesMinutes / lifespanInMinutes) * 100; | ||
| totalPercentage += percentage; | ||
|
|
||
| console.log(`${series.title} took ${percentage.toFixed(6)}% of your life.`); |
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.
Numbers with .toFixed(6) precision look too long
| days: 1, | ||
| hours: 0, | ||
| minutes: 9, | ||
| }, |
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.
| }, | |
| } |
| @@ -0,0 +1,46 @@ | |||
| const seriesDurations = [ | |||
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.
If the series array is empty it will show 0%. Maybe add a check that if the array is empty, it will display for example, “There are no series”?
This is not necessary, but will make the code more reliable
| if (totalDuration >= usageLimit) { | ||
| console.log("You have reached your limit, no more smartphoning for you!"); | ||
| } | ||
|
|
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.
| } |
|
|
||
|
|
||
| function addActivity(date, activity, duration) { | ||
| if (!date || !activity || !duration) { |
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.
The if (!date || !activity || !duration) prints a message, but does not stop the object from being added
| } | ||
|
|
||
|
|
||
| function showStatus() { |
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.
Due to undefined in duration, the reduce method produces NaN, which breaks the output. For example, the current code counts 30 + undefined + 40 + 40 = NaN
|
|
||
|
|
||
| function showStatus() { | ||
| if (activities.length == 0) { |
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.
| if (activities.length == 0) { | |
| if (activities.length === 0) { |
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.
Great job, your function calculates the time correctly and outputs “8 hours and 38 minutes”. The logic with Math.floor and Math.round for hours and minutes works perfectly
|
|
||
| const nameToRemove ="Ahmad" | ||
| const index = names.indexOf("Ahmad"); | ||
| if (name >-1){ |
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.
| if (name >-1){ | |
| if (index >-1){ |
Hello,
Please review my javascript-javascript1-week3 homework.
Thank you very much!