Skip to content

Conversation

@codebynina
Copy link
Owner

Hello,

Please review my javascript-javascript1-week3 homework.

Thank you very much!

Copy link

@l0rians l0rians left a 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;
Copy link

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

Suggested change
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.`);
Copy link

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,
},
Copy link

Choose a reason for hiding this comment

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

Suggested change
},
}

@@ -0,0 +1,46 @@
const seriesDurations = [
Copy link

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!");
}

Copy link

Choose a reason for hiding this comment

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

Suggested change
}



function addActivity(date, activity, duration) {
if (!date || !activity || !duration) {
Copy link

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() {
Copy link

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) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
if (activities.length == 0) {
if (activities.length === 0) {

Copy link

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){
Copy link

@l0rians l0rians Feb 21, 2025

Choose a reason for hiding this comment

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

Suggested change
if (name >-1){
if (index >-1){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants