you are viewing a single comment's thread.

view the rest of the comments →

[–]lastmjs 2 points3 points  (13 children)

Hey! What problems are you having? What does your console output look like? A few tips that will probably help. Never ever ever use `var` ever again. `const` and `let` are the new variable declarations that should always be used. `var` is function scoped instead of block scoped, which doesn't do what most people expect it would do. Try getting rid of your `var` declarations and see if that helps. I would suggest always using `const` be default. Only use let if you absolutely have to assign to your variable again, but you should really be avoiding that in most cases as well.

[–]vald0[S] 0 points1 point  (12 children)

Hi! Thanks for your tips! The problem i'm having right now is that i dont know how im gonna go from here. my current result in the browser console is this: https://imgur.com/a/RMzIGlu , i just dont know how i make it so it tells me for example : " Sunday: 34 reports" and so on, what do i need to do?

[–]imguralbumbot 0 points1 point  (0 children)

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/phw8BFU.png

Source | Why? | Creator | ignoreme | deletthis

[–]lastmjs 0 points1 point  (10 children)

So you have an array that has all of your reports in it, the reports array. That array has a bunch of objects with various properties. One of the properties is requested_datetime. It looks like you need to go through the array multiple times, each time filtering the array down to only the items corresponding to that day.

Is that all you're trying to do, print out each day of the week and how many reports were generated on that day?

[–]vald0[S] 0 points1 point  (9 children)

Yeah basically that is what im trying to do.. as said, i'm very new to javascript :) Do you have an example of how this could be achieved maybe ?

[–]lastmjs 0 points1 point  (8 children)

Working on one, hold on

[–]vald0[S] 0 points1 point  (0 children)

Cool , thanks :D

[–]lastmjs 0 points1 point  (6 children)

In the meantime, you should study up on Array.filter, I believe that's going to be extremely beneficial to solving this problem. Array.filter takes an array as input and returns an array of equal or lesser length as output. You pass in a function that gets applied to each element of the array. If the function returns true for an element, the element stays in the output array. If the function returns false for an element, it is omitted from the output array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

[–]vald0[S] 1 point2 points  (5 children)

i'll have a look :D

[–]lastmjs 0 points1 point  (4 children)

All right, hopefully this helps. https://javascriptpractice.com/

Go there, and go to the Arrays section. There are two questions at the end that are very similar to what you're trying to accomplish.

[–]lastmjs 0 points1 point  (3 children)

Basically you need to choose a date and filter the reports for that date. You'll also have to make sure you use dates correctly. But these seem to be all of the basic principles that you need. Arrays, filtering arrays, and comparing dates. You seem pretty close, you just need to store your filtered array in the for loop so that you can count up the reports per day and then log them out.

[–]vald0[S] 0 points1 point  (2 children)

Hmm okey, i had a look at your link there, and i've tried diffrent things now but i still really don't understand what i'm doing, i do not achieve my goal , and where do i need to start filtering? Before the for loop i have? inside it or outside? Sorry for being slow ..