score:7

Accepted answer

part of your problem stems from pushing the same object into the 2 different arrays here:

    for(i = 0; i < languages.length; i++) {
        currentlanguage = new language(languages[i].language)

        learninglanguages.push(currentlanguage)
        nativelanguages.push(currentlanguage)
   }

this does not copy currentlanguage into each, it pushes references of the same object into each.

then whatever you do to that object reference in one will be reflected in the other

try making 2 separate objects

    for(i = 0; i < languages.length; i++) { 
        learninglanguages.push(new language(languages[i].language))
        nativelanguages.push(new language(languages[i].language))
   }

the use of global variables will also get you into trouble...don't do it!

score:1

learninglanguages = []
nativelanguages = []

these two variables look like they are not defined in an above scope - thus the second xhr call does not know about these variables.

second piece of the answer is reference to the same object instance, with the same "count" attribute touched twice.

i'd suggest two options are here:

  • use new language(...) for each of these two arrays separately
  • or have a separate counter for each type of native/learning counts.

Related Query

More Query from same tag