Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo, almost identical lines of code with different results?
    primarykey
    data
    text
    <p>I'm learning how to do code for web development, and I have run into a problem. Two almost identical lines of code are giving me different results:</p> <pre><code>for(i=0; i&lt;=lunarSpells.length; i++){ document.getElementById(lunarSpells[i]).innerHTML = Math.ceil(xpLeft/document.getElementById(lunarSpells[i]+"XP").innerHTML); } for(i=0; i&lt;=standardSpells.length; i++){ document.getElementById(standardSpells[i]).innerHTML = Math.ceil(xpLeft/document.getElementById(standardSpells[i]+"XP").innerHTML); } </code></pre> <p>Unsure of its importance, but the idea is to take an element from the array, find it in the document, and then fill in the table accordingly. Here are the arrays:</p> <pre><code>var lunarSpells = ["cureOther", "NPCContact", "curePlant", "monsterExamine", "bakePie", "cureMe", "TGMoonclan", "TPMoonclan", "TGBarbarian", "superglass", "TPKhazard", "TGKhazard", "dream", "stringJewellery", "statRestorePotShare", "statSpy", "TPBarbarian", "TPWaterbirth", "cureGroup", "TGWaterbirth", "humidify", "hunterKit", "fertileSoil", "plankMake", "TPCatherby", "TGFishingGuild", "TGCatherby", "boostPotionShare", "TPIcePlateau", "energyTransfer", "healOther", "TGIcePlateau", "vengeanceOther", "vengeance", "healGroup", "spellbookSwap", "magicImbue", "TPFishingGuild"] var standardSpells = ["confuse", "sapphire", "weaken", "bananas", "curse", "lowAlch", "TPVarrock", "emerald", "TPLumbridge", "TPFalador", "TPHouse", "superheat", "TPCamelot", "ruby", "TPArdougne", "highAlch", "earth", "water", "diamond", "TPWatchtower", "peaches", "TPTrollheim", "fire", "TPApe", "vulnerability", "air", "dragonstone", "enfeeble", "TOLumbridge", "stun", "TOFalador", "onyx", "TOCamelot"] </code></pre> <p>So my question, is WHY is the lunarspells variable working, while the standardspells variable is not? Any help is much appreciated, as I am still quite new to HTML and JS.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload