I'm pretty new at Javascript (and web design). I'm trying to design an interactive webgame for purely educational purposes (I'm a professional educator. Most of my programming experience in creating self-contained Java apps).
In my HTML document, I have some internal script that creates a boolean array called hypotheses. I also have an external JS script called game.js that produces some visual output based on its own array, also called hypotheses, which I call using . I would like to update the external array from the internal one, but nothing I try works. The internal script is called from a form.
<script>
var testedhypotheses = [];
var hypotheses = hypArray(); //load up a boolean array of hypotheses.
function testHypothesis(theform, numTest){
//update numbers
theform.newhyp.value = theform.newhyp.value - numTest;
//move hypotheses from one list to the other
for(var i; i < numTest; i++){
testedHypotheses.push(hypotheses.pop());
}
//pass the array of hypotheses to the external function.
updateHyp(testedHypotheses);
</script>
The function definitely works, and items are being moved from one array to another. However, the function updateHyp() is not being called. I've tried it a bunch of ways, but the most recent was to include this in the HTML file:
<script type="text/javascript" src="game.js">
var updateHyp = function (hypArray) {
updateHypotheses(hypArray);
};
</script>
Inside game.js, I have the following code:
var updateHypotheses = function(hypArray){
var end = hypotheses.length;
for(var i = end; i < hypArray.length; i++){
var ind = hypotheses.length;
var tf = hypArray[i];
var rando = Math.random();
var res rando < 0.5 ? 1 : 0;
hypotheses.push(new Hypothesis(i, tf, res));
}
}
};
It seems that this code is never getting called. Any help would be much appreciated!!!