I got an external JS file which includes JSON array and functions helps me to pick a random set of variables. When I tried to generate the result in the main HTML file, nothing showed in the p tag. Am I mismatching any objects or variables?
Short Example of HTML file in body section
<p id="result"></p>
<script src="myJSfile.js" type="text/javascript">
<script language="javascript" type="text/javascript">
document.getElementById("result").innerHTML = lottery(selected.name + selected.age);
</script>
Short Example of External JS file
function lottery() {
var from, to, selected=new Array();
var person=
[
{"name":"Georgia","age":"45"},
{"name":"John","age":"38"},
{"name":"Michael","age":"29"},
];
if (arguments[0] == "all") {
from=0;
to=person.length;
}
else {
from=Math.floor(Math.random()*3);
to=Math.floor(Math.random()*3+1);
}
for (i=0; i<to; i++) {
selected[i]=person[from];
from=(from+1)%3;
}
return selected;
}