Click here to Skip to main content
14,358,347 members

JavaScript

 
GeneralRe: unexpected result function autocomplete() Jquery Pin
serenimus22-Nov-18 7:13
memberserenimus22-Nov-18 7:13 
GeneralRe: unexpected result function autocomplete() Jquery Pin
Richard Deeming22-Nov-18 9:41
mveRichard Deeming22-Nov-18 9:41 
GeneralRe: unexpected result function autocomplete() Jquery Pin
serenimus1-Dec-18 1:19
memberserenimus1-Dec-18 1:19 
QuestionHello Pin
Member 1406106620-Nov-18 9:15
memberMember 1406106620-Nov-18 9:15 
QuestionJavascript help Pin
ghazabaz8-Nov-18 16:54
memberghazabaz8-Nov-18 16:54 
AnswerRe: Javascript help Pin
Richard Deeming9-Nov-18 4:49
mveRichard Deeming9-Nov-18 4:49 
QuestionRe: Javascript help Pin
ghazabaz9-Nov-18 6:55
memberghazabaz9-Nov-18 6:55 
AnswerRe: Javascript help Pin
Richard Deeming9-Nov-18 8:48
mveRichard Deeming9-Nov-18 8:48 
ghazabaz wrote:
Use those two parameter values and the Math.floor() and Math.random() methods to return a random integer within the specified range.

ghazabaz wrote:
function randomInt(lowest, size) {
  size = Math.floor(Math.random() * 10);
  lowest = Math.floor(Math.min(size));
}

Again, that function isn't returning anything. And you're ignoring the parameters - you immediately overwrite size with a random value, and then overwrite lowest with the value of size.

Look at the demo on the MDN site[^] again:
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

Breaking that down a bit:
function getRandomInt(max) {
    var number = Math.random();             // Generate a random number greater than or equal to 0, and less than 1.
    var maxInt = Math.floor(max);           // Remove any decimal part of the largest number to return.
    var numberInRange = number * maxInt;    // Translate the random number to a range that's greater than or equal to 0, and less than maxInt.
    var result = Math.floor(numberInRange); // Remove any decimal part of the result.
    return result;                          // Return the result.
}

That's almost exactly what you're trying to do. The difference is, you need to translate the random number to a range that's greater than or equal to Math.floor(lowest), and less than (Math.floor(lowest) + Math.floor(size)). You can use some fairly simple arithmetic to do that. Smile | :)



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

Generalguidence for the begginners Pin
Kshitiz Thapa2-Nov-18 4:16
memberKshitiz Thapa2-Nov-18 4:16 
GeneralRe: guidence for the begginners Pin
Richard MacCutchan2-Nov-18 5:00
protectorRichard MacCutchan2-Nov-18 5:00 
SuggestionRe: guidence for the begginners Pin
CHill6015-Nov-18 22:46
protectorCHill6015-Nov-18 22:46 
QuestionLoops Pin
Member 1403490227-Oct-18 6:06
memberMember 1403490227-Oct-18 6:06 
AnswerRe: Loops Pin
Richard MacCutchan27-Oct-18 6:54
protectorRichard MacCutchan27-Oct-18 6:54 
QuestionSTOP VALIDATION Pin
Member 1344978425-Oct-18 1:44
memberMember 1344978425-Oct-18 1:44 
AnswerRe: STOP VALIDATION Pin
Afzaal Ahmad Zeeshan25-Oct-18 3:40
mveAfzaal Ahmad Zeeshan25-Oct-18 3:40 
Questionno me funciona funcion autocomplete Jquery Pin
serenimus20-Oct-18 9:53
memberserenimus20-Oct-18 9:53 
AnswerRe: no me funciona funcion autocomplete Jquery Pin
Nelek20-Oct-18 9:59
protectorNelek20-Oct-18 9:59 
QuestionMap JSON data file with dates and multiple string value pairs to Angular/Chart.js Pin
Member 1201357914-Oct-18 23:08
memberMember 1201357914-Oct-18 23:08 
Questionaspx file don't open in chrome Pin
anasr200010-Oct-18 3:22
professionalanasr200010-Oct-18 3:22 
Questiontest regexep javascript Pin
Alboyz5-Oct-18 5:31
memberAlboyz5-Oct-18 5:31 
AnswerRe: test regexep javascript Pin
Richard Deeming5-Oct-18 5:48
mveRichard Deeming5-Oct-18 5:48 
GeneralRe: test regexep javascript Pin
Alboyz5-Oct-18 6:02
memberAlboyz5-Oct-18 6:02 
GeneralRe: test regexep javascript Pin
uxotucung9-Nov-18 4:09
memberuxotucung9-Nov-18 4:09 
QuestionAdding a list of files to the array and displaying them in the component Pin
Member 140077214-Oct-18 5:33
memberMember 140077214-Oct-18 5:33 
QuestionDate picker style not showing Pin
thepast24-Sep-18 9:21
memberthepast24-Sep-18 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.