Two js files ( can't see to add characters but I'll try)

Okay, last question for now :slight_smile:

I’m working from 2 .js files – I have another pen and I listed in the settings for “extermal.”

I can pull “math facts” from that and use it in the other .js file. However, I put an array of facts in the external .js and I’m not able to use it. Do I need to figure out my mistake … or is it a thing I can’t do?

I assume that when I change something about the variable in one .js file it won’t change it in the other… but is there some way to say, save the facts I missed in an external .js file to use in a future quiz?

https://codepen.io/geonz/pen/wvvJVxZ is the second .js; https://codepen.io/geonz/pen/jOOwzmw is the main one

I went to settings and included that as external file.

ah :wink: I peeked back at your first “how to” – and yea, I’d missed the .js tag (tho’ I did wonder!) I’m fascinated that it worked at all !

… but it still doesn’t work. I can get individual facts from the other .js but not facts from the array.
This is the line in the second .js file; its copied and pasted into the main one b/c otherwise I just get the original question again and again; I am trying to set this up right :wink:

`ruleFactsGroup = [ fact0byRand3, fact0byRand2, fact1byRand1, fact1byRand2, fact10byRand1, fact10byRand2];```


This is the function


... 
function practiceMissed() {
  if (reviewStage === 1) {
    currentFact =
      ruleFactsGroup[Math.floor(Math.random() * ruleFactsGroup.length)];
  } else if (reviewStage === 2) {
    currentFact = justMissed;
  }.`

If I comment out line 16 in https://codepen.io/geonz/pen/jOOwzmw … then when I make an error and submit it, then correct it, I keep getting the same problem.

If the array is there, then if I make an error, submit it, then correct it, I get an easy problem and then another practice with the one I missed.

(the two pens are identical … I forked before trying to do the next thing…)… well, they were identical 'til I mucked up the other one…

(thanks tons for this much help)

Okay, I must have forked before fixing the .js part… but now it’s fixed… but the main quiz can’t get facts from the array on the ‘just facts’ .js file.

I didn’t want to have to copy and paste all the math facts… so I made a file for them that all the other quizzes could go to for them. That works even with the error!
That particular array is one I will be using on lots of different quizzes, so I had hoped to be able to say “make the current fact a random one from that array” and get the array from the other .js just as I got all the other facts.

It doesn’t work. I have the exact array in both files. (line 44) in the just facts)I’m wondering if it’s a limitation of external files.

(I also wish I could put an array on that “all the facts” list, and add “these are the ones missed” so that in other quizzes they could be found, but that seems unlikely without some bigger nesting and reorganization.)

You need to debug your practiceMissed function. When you miss a question, this function executes, . If reviewStage is equal to 1, then you are assigning the following to currentFact.

ruleFactsGroup[Math.floor(Math.random() * ruleFactsGroup.length)];

The problem is, ruleFactsGroup is an empty array when you comment out line 16, because you assign it to be an empty array on line 5. Since it is an empty array, you are going to assign ‘undefined’ to currentFact when this function executes. Unless you populate ruleFactsGroup (in the current pen or the external js file) with some question elements, this is going to continue to be a problem.

Line 5 just needed to go away … sincde that var is in the other .js :slight_smile: Works like it should, now!

(Now for making little objects from the big ones… or, rather, now for a bike ride :))

Makes sense! Another thing to put on my Learn And Apply List :slight_smile: