var gases = [ 'O2','SO2','H2S','Cl2','NH3','N2','CO','CO2','H2S','NO','N2O','AsH3','F2','Cl2O','ClF3','PH3','SiH4','Si2H6','HF','CH4','H3CCH=CH2','HC#CH', "H2", "COCl2", "NO2" ] function getRandomReaction() { var total = getTotalLength(actQuestion.reactions); var index = Math.floor(total*Math.random()); var index2 = index; var findex = 0; while (actQuestion.reactions[findex].length < index2) { index2 -= actQuestion.reactions[findex].length; findex++; } var final = actQuestion.reactions[findex][index2] return reactions[findex][final]; } function getTotalLength(field) { var out = 0; for (var i = 0; i < field.length; i++) { out += field[i].length; } return out; } function getReagent(index) { console.log("index " + index) return actQuestion.reaction.reagents[index]; } function getProduct(index) { return actQuestion.reaction.products[index]; } function getSolubleProduct() { var solubles = [] for (var i = 0; i < actQuestion.reaction.products.length; i++){ var item = actQuestion.reaction.products[i]; if (item.soluble == true) { solubles.push(i) } } var index = Math.floor(solubles.length*Math.random()); return actQuestion.reaction.products[solubles[index]]; } function getSolubleReagent() { var solubles = [] for (var i = 0; i < actQuestion.reaction.reagents.length; i++){ var item = actQuestion.reaction.reagents[i]; if (item.soluble == true) { solubles.push(i) } } var index = Math.floor(solubles.length*Math.random()); return actQuestion.reaction.reagents[solubles[index]]; } function getGasReagent() { var gases = [] for (var i = 0; i < actQuestion.reaction.reagents.length; i++){ var item = actQuestion.reaction.reagents[i]; if (item.gas == true) { gases.push(i) } } var index = Math.floor(gases.length*Math.random()); return actQuestion.reaction.reagents[gases[index]]; } function getGasProduct() { var gases = [] for (var i = 0; i < actQuestion.reaction.products.length; i++){ var item = actQuestion.reaction.products[i]; if (item.gas == true) { gases.push(i) } } var index = Math.floor(gases.length*Math.random()); return actQuestion.reaction.products[gases[index]]; } function getRandomReagent(index) { var field = actQuestion.reaction.reagents; var index = Math.floor(field.length*Math.random()); return field[index]; } function getRandomProduct(index) { var field = actQuestion.reaction.products; var index = Math.floor(field.length*Math.random()); return field[index]; } /* function getHTMLFormula(comp) { var text = comp.formula.replace(/(\d+)/g, "$1"); return text; }*/