|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
![]() ![]() Here goes: /* 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) { var prevArray = new Array(previousSelections); parseFloat(newSelection); if (newSelection == previousSelections) { document.write('already selected.', ''); return true; } else { document.write('not been selected.', ''); return false; return newSelection; } } /* The function prompts users to select numbers from a pool of balls The function takes two arguments: the highest number in the pool of balls the number of balls to be selected The user is prompted to make choices. A check is made that a choice is not a duplicate. The user is reprompted to make a choice if a selection has been selected already The function returns an array of numbers selected by the user */ function selectNum(highNumber, numberToSelect) { // Alert user to the valid range of balls to be selected window.alert('Enter numbers between 1 and ' + highNumber + '.', ''); parseFloat(numberToSelect); var numArray = new Array(numberToSelect); var current = 0; //not sure about this var selectArray = new Array(current); //not sure about this for (var index = 1; index < numberToSelect; index = index + 1) { numSelArray[index] = parseFloat(window.prompt('Please enter your ball selection.', '')); while (isAlreadySelected(current, numSelArray[index]) == true)//got this incorrect { window.alert('Current ball has already been selected.', ''); numSelArray[index] = parseFloat(window.prompt('Please enter your ball selection.', '')); } selectArray[current] = numSelArray[index]; } return selectArray(current);//and this is not right } </SCRIPT> </HEAD> <BODY>//the rest of this is ok, but provided to show what to expect <STRONG>A test of the function selectNumbers()<BR></STRONG> <FORM NAME = "lotteryForm"> <INPUT TYPE = "button" NAME = "selectBalls" VALUE ="Select your Numbers!" ONCLICK = "var sel = selectNum(20, 8); window.prompt('You selected: ' + sel);"></P> |
#2
| |||
| |||
Re: JavaScript function help yoiu should use the .equals() instead of == . The reason is that == is best used for numbers while .equals makes a direct comparison. |
#3
| |||
| |||
Re: JavaScript function help The .equals() function does not work with javascript, it works with java. Thanks anyway. ![]() |
#4
| |||
| |||
Re: JavaScript function help Yeah i miss read the title thought it said JAVA |
![]() |
|
Tags: function, javascript |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Passing XSL value to javascript function | Steadfast | Software Development | 6 | 13-05-2010 11:51 PM |
c# function equivalent to gettime function in javascript | Omaar | Software Development | 4 | 10-03-2010 10:44 PM |
Eval function in javascript | Solaris | Software Development | 5 | 02-03-2010 05:59 PM |
Javascript isNull function | Chrisch | Software Development | 3 | 11-11-2009 02:51 PM |
JavaScript Sleep Function | DARIELLE | Software Development | 3 | 29-06-2009 09:30 AM |