How to nested for loops, browser crashing, help plez

hey there. I am trying to assign the values from the flavors array to the points. I have been attempting various iterations of nested for loops, only to the avail of freezing my browser over and over again. Could someone explain to me the best way to do this?

https://jsfiddle.net/r2k1Lspb/

Hi,

I don’t see your code. Did you try something already?
Also, what is the purpose of your code?

Best!
Sebastian

I am trying to assign the x and y values from the flavors array to the cx and cy values for each point.

Well, basically, this should do it:

let n = 0;

for (const sets of flavors) {
  for (const set of sets) {
    point[n].setAttribute('cx', set.x);
    point[n].setAttribute('cy', set.y);
    n++;
  }
}

I am not sure why the fiddle is so slow - I replicated it on my computer and it works charmingly well.

If you’re not sure how to do that, let me know. :slight_smile:

1 Like

face palm! I totally forgot about for of loops…

Thank you. this really helped clean up my code.

Most welcome!
I’d be curious to see the final result of your work - what’s it about?

Thanks. I’m making a flavor tasting web app. During my day job, I am a cheese monger. I am making a cheese blog and would like to do cheese reviews in the blog. Based off of this tasting note card

this is my current iteration.

here is the link to the other thread that has been tracking the project from the start

Let’s stick to one thread pre project please. Thanks!

alright, for sure!

:100: :100: :100:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.