HI all,
Really struggling to find (what I think) are syntax errors in this code.
I'm getting a ; expected on line 42 (anArray = new Array[numberToSelect];) and then when i click the button I get an object expected error. I have deleted it and started again but still need your help!
Regards
Brendan
Really struggling to find (what I think) are syntax errors in this code.
I'm getting a ; expected on line 42 (anArray = new Array[numberToSelect];) and then when i click the button I get an object expected error. I have deleted it and started again but still need your help!
Regards
Brendan
Code:
<HTML> <HEAD> <TITLE>M150 TMA 5 : Programming : Task 3 - User selection of balls</TITLE> <SCRIPT language="JavaScript"> /* Determines if a given ball has already been selected. The function takes two arguments: a whole number which is a new selection an array which contains previous selections. The function returns: true if the new selection exists in the previous selections false otherwise */ function isAlreadySelected(newSelection, previousSelections) { for(var i = 0; i < previousSelectons.length; i = i + 1) { if(newSelection == previousSelction[i]) { return true; } else { return false; } } } function selectNumbers(highNumber, numberToSelect) { anArray = new Array[numberToSelect]; for(int z = 0; z < numberToSelect; z = z + 1) { anArray[z] = 0; } for(var y = 0; y < numberToSelect; y = y + 1) { var anEntry = parseFloat(window.prompt('please enter your number', '')); while(isAlreadySelected(anEntry, anArray)) { anEntry = parseFloat(window.prompt('You have already entered that number - please enter another number')); } anArray[y] = anEntry; } return anArray } </SCRIPT> </HEAD> <BODY> <STRONG>A test of the function selectNumbers()<BR></STRONG> <FORM NAME = "lotteryForm"> <INPUT TYPE = "button" NAME = "selectBalls" VALUE ="Select your Numbers!" ONCLICK = "var selection = selectNumbers(10,5); window.alert('You selected: ' + selection);"> </FORM> </BODY> </HTML>
Comment