object error
Collapse
X
-
Since this is a course, we can't give you the answer, but we can help you solve it. The first thing to do is describe what your code should be able to do, what it currently does and any errors you see in the error console.Comment
-
Andy help?
Code:<!-- COMPLETE THE ONCLICK EVENT HANDLER TO INVOKE lotteryDraw() WITH ARGUMENTS TAKEN FROM THE FORM INPUT TEXT BOXES --> <INPUT TYPE = "button" NAME = "drawBalls" VALUE ="Draw the Balls!" ONCLICK = "document.lotteryForm.drawnNumbersTextBox.value = lotteryDraw().value">
Comment
-
wrong output!! ??
Code:function getRandomNumber(aNumber) { var getRandomNumber = Math.floor(Math.random()); return aNumber; } function lotteryDraw(highBall, numberToDraw) { var numberPool = new Array(highBall); var sizeOfPool = highBall; var drawnNumbers = new Array(numberToDraw); for (var index = 0; index < highBall; index = index + 1) { //creates an array of all the numbers that can be possibly drawn ! numberPool[index] = index + 1; } for (var drawnBall = 0; drawnBall < numberToDraw; drawnBall = drawnBall + 1) { var randomNumber = getRandomNumber(sizeOfPool); drawnNumbers[drawnBall] = numberPool[randomNumber]; numberPool[randomNumber] = numberPool[sizeOfPool - 1]; sizeOfPool = sizeOfPool - 1; } lotteryForm.drawnNumbersTextBox.value = drawnNumbers; } </SCRIPT> </HEAD> <BODY> <STRONG>A test of the function lotteryDraw()<BR></STRONG> <FORM NAME = "lotteryForm"> <P> Total Number of Balls in Pool: </P> <P> <INPUT TYPE = "text" NAME = "numberOfBallsTextBox" SIZE ="2" MAXLENGTH = "2"> </P> <P> Number of Balls to Draw: </P> <P> <!-- Note the SIZE attribute, whose value determines the size in characters of a text box and the MAXLENGTH attribute, whose value constrains the length in characters of the allowed input --> <INPUT TYPE = "text" NAME = "ballsToDrawTextBox" SIZE = "1" MAXLENGTH = "1"> </P> <!-- The RESET input type creates a button which, when clicked, resets a form to its original state --> <INPUT TYPE = "reset" NAME = "resetButton" VALUE = "Clear Form"> <!-- COMPLETE THE ONCLICK EVENT HANDLER TO INVOKE lotteryDraw() WITH ARGUMENTS TAKEN FROM THE FORM INPUT TEXT BOXES --> <INPUT TYPE = "button" NAME = "drawBalls" VALUE ="Draw the Balls!" ONCLICK = " var first = document.lotteryForm.ballsToDrawTextBox.value; var second = document.lotteryForm.numberOfBallsTextBox.value; lotteryDraw(first, second)"> <P> Drawn Numbers: </P> <P> <INPUT TYPE = "text" NAME = "drawnNumbersTextBox" SIZE = "30" MAXLENGTH = "30" > </P> </FORM> </BODY> </HTML>
Comment
-
Return of true!
You may be able to help me again though lol. Im stuck on this one. I keep getting a return of true after the 1st input!!
Any ideas!!
Cheers
Code:function isAlreadySelected(newSelection, previousSelections) { for(var index = 0; index < previousSelections.length; index = index + 1) { if(newSelection == previousSelections[index]) { return true; } else { return false; } } }
Comment
-
Stuck
Code:<HTML> <HEAD> <TITLE>M150 TMA 5 : Programming : Task 3 - User selection of balls</TITLE> <SCRIPT language="JavaScript"> function isAlreadySelected(newSelection, previousSelections) for (var index = 1; index <= previousSelections.length;index = index+ 1) { if (newSelection == previousSelections) { return true; } } function selectNumbers(highNumber, numberToSelect) { var selectedArray = new Array(numberToSelect); for (var index = 0; index < numberToSelect; index = index + 1) { selectedArray[index] = 0; } for(var selected = 0; selected < numberToSelect; selected = selected + 1) { var anEntry = parseFloat(window.prompt('please select a number', '')); while(isAlreadySelected(anEntry, selectedArray)) { anEntry = parseFloat(window.prompt('You have already entered that number!Please select another number.')); } selectedArray[index] = anEntry; } return selectedArray } } </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>
Hi guys, can't get this to work at all, I think I'm making progress, now feels like Im back to square one :( Please help!Comment
-
As I've mentioned earlier in the thread, since this is coursework/homework, we can only guide you, not show you the answer. For that to work, you need to show what you've tried, what you expect to happen, what's happening instead, the exact problems you're having and any error messages. Just saying it doesn't work isn't enough. Help us to help you.Comment
Comment